The previous post was on creating a minimal TIBCO RV listener. So naturally it’s time to look at creating a minimal TIBCO RV “sender”. In other words, creating a message and sending it.
Note: The initial code was take from the C# TIB RV samples, but I wanted to distil these to a quick and simple step by step guide.
For this sample we’ll create a Console application in C# and we’ll assume you are getting the server, network etc. values from some key/value mechanism, whether this is a command line parser or config is down to your specific implementation.
So create a Windows Console project then follow the steps below (the full code will be listed at the end of this rambling)
In case you’ve come to this post without first reading the post on creating a minimal listener, I will repeat a fair amount of code/steps from that post here.
- Add references to TIBCO.Rendezvous and ensure that TIBCO.Rendezvous.netmodule resides in the same folder as TIBCO.Rendezvous (just in case you’re not referencing the TIB RV installation itself
- For this simple example we’ll hard code a few variables
string server = arguments["server"]; string network = arguments["network"]; string daemon = arguments["daemon"];
-
Next we need to open the Rendezvous environment using
TIBCO.Rendezvous.Environment.Open();
The above code should be enclosed in a try..catch block, either enclosing all of the following code or if you want the granularity, then each line in essence. For now we’ll just assume it’s all in a try..catch block
-
We now need to create the transport
Transport transport = new NetTransport(service, network, daemon);
-
Now it’s time to create the message. The subject is set to “myapp.mysubject” and we add some data to a new field we’ve created named “Data”
Message message = new Message { SendSubject = "myapp.mysubject" }; message.AddField("Data", "Some Data");
-
To send the message is simply a case of
transport.Send(message);
-
Finally when we’ve finished with RV we need to close the environment with
TIBCO.Rendezvous.Environment.Close();
Before we look at the full code, here’s what the listener shows us if we listen to “myapp.>”
2013-11-21 15:58:49 (2013-11-21 15:58:49.281000000Z): subject=myapp.mysubject, message={Data=”Some Data”}
And as promised, the full code is
public void Process(CommandLineArguments arguments) { string service = arguments["server"]; string network = arguments["network"]; string daemon = arguments["daemon"]; try { TIBCO.Rendezvous.Environment.Open(); Transport transport = new NetTransport(service, network, daemon); Message message = new Message { SendSubject = "myapp.mysubject" }; message.AddField("Data", "Some Data"); transport.Send(message); } catch (Exception e) { Console.WriteLine(e.Message + "\n\n" + e.StackTrace); } finally { TIBCO.Rendezvous.Environment.Close(); } }