Happy New Year!
Wow, it’s been a while since I've had a chance to write a post as it’s been a whirlwind beginning of a year already!
Last week we had a chance to visit 6 European cities in 6 days as we talked to a number of companies about using our Enterprise Application Fabric (EAF) to solve a wide variety of problems. So thank you to everyone we talked to in Prague, Munich, Frankfurt, Erlangen, Zurich and London! (We didn’t intend to go to Zurich, but the events in London on January 16th gave us a chance to experience the cities hospitality…)
We have also had a large number of new product evaluations taking place over the last couple of weeks, so I wanted to post a couple of Visual Studio project templates that I use for training purposes in an effort to help those of you who are using Visual Studio.
This first example is a simple Hello World that illustrates how we use annotations and Reflection to inject and retrieve values from a class. While my example uses simple data types, you should know that we support rich data types, custom data structures and can even pass native data types between .NET and Java applications within a single EAF application, so goodbye isolated application deployment environments and hello fabric!
I’m also using our new MulticastSocket API for multicast messaging. This API is one of the new features that can be found in our upcoming 3.7 release.
To use this C# project temple, put this zip file into your \Visual Studio\Templates\Project Templates directory and select the File / New Project menu item from Visual Studio, then select Fabric_Task_HelloWorld from the My Templates Section of the New Project dialog box.
using System; using System.Collections.Generic; using System.Text; using Appistry.Task; using Appistry.Implementation; namespace HelloWorldObject { public class Class1 { // MulticastSocket is a new API that allows Tasks // to send multicast messages to Log_monitor via // the send method and also provides an API for // retreiving the local machines TCP/IP address private static MulticastSocket messageSocket; private static System.Net.IPAddress localIP; public static void OnStartup() { messageSocket = new MulticastSocket("239.255.0.78", 4001); localIP = MulticastSocket.GetMachineIPAddress(); messageSocket.Send("Setup done in: " + localIP.ToString()); } // The ITaskRequest annotated with TaskRequest works // just like the v2.4 product (eg. request["MyValue"]) private ITaskRequest request; [TaskRequest] public ITaskRequest mRequest { get { return request; } set { request = value; } } // The TaskProperty annotation allows you to pass fabric // request values to existing class properties. private int myVar; [TaskProperty] public int MyProperty { get { return myVar; } set { myVar = value; } } // You can also add TaskReturnValue and TaskParameters to pass // fabric request values to your existing applications [return: TaskReturnValue("Hello_Return")] public string Hello([TaskParameter("in_arg")] string in_arg) { messageSocket.Send("Hello from:" + localIP.ToString() + " Request ID:" + request.Id); return myVar.ToString() + " " + in_arg + " " + localIP.ToString(); } } }
The final thing I want to point out is that I like to package and deploy my applications during the post-build event. So I have included the following commands in the projects Build Events -
fabric_pkg CS_App.xml
fabric_ctl -ufabric-admin/fabric-admin -d239.255.0.1:30000 deploy HelloWorld_App.fabric
You can use the log monitor to watch the fabric workers messages -
C:\log_monitor 239.255.0.78:4001
To call this fabric application from a client, create a C# Console Application and add the Appistry.NET dll found in the \Program Files\Appistry\System directory to your projects references. Here is the simple client for making a single fabric call -
using System; using System.Collections.Generic; using System.Text; using Appistry.FabricAPI; namespace Fabric_Client_Sync { class Fabric_Client_Sync { static void Main(string[] args) { Fabric fabric = new Fabric("239.255.0.1", 31000, Encryption.NONE); FabricRequest request = new FabricRequest("Hello_App", "CS_Process"); try { //Put the request[""] values being sent to your task/process flow here request["MyProperty"] = 100; request["in_arg"] = "Hello World"; fabric.Execute(request); // Synchronous invocation //Retrieve your results here Console.WriteLine(String.Format("{0}", request["Hello_Return"])); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { request.Dispose(); } Console.WriteLine("All done, press any key to continue.."); Console.ReadKey(); } } }
We have a lot of great plans for 2008 and one of my New Years resolutions is to publish a lot more code this year, so get ready!
I also wanted to thank Manoli.net for a feature they have that formats and maintains the color coding for C# code. (http://www.manoli.net/csharpformat/ ) It really makes my code look great! (OK, well at least it’s aesthetically pleasing… )
Let me know if you have any questions or comments...
Until next time!!
Mark







