{"id":787,"date":"2013-11-21T16:20:08","date_gmt":"2013-11-21T16:20:08","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=787"},"modified":"2020-10-08T15:32:23","modified_gmt":"2020-10-08T15:32:23","slug":"minimal-steps-to-create-a-tibco-rv-message-and-send-it","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/minimal-steps-to-create-a-tibco-rv-message-and-send-it\/","title":{"rendered":"Minimal steps to create a TIBCO RV message and send it"},"content":{"rendered":"<p>The previous post was on creating a minimal TIBCO RV listener. So naturally it&#8217;s time to look at creating a minimal TIBCO RV &#8220;sender&#8221;. In other words, creating a message and sending it.<\/p>\n<p><em>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.<\/em><\/p>\n<p>For this sample we\u2019ll create a Console application in C# and we\u2019ll 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.<\/p>\n<p>So create a Windows Console project then follow the steps below (the full code will be listed at the end of this rambling)<\/p>\n<p>In case you&#8217;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. <\/p>\n<ol>\n<li>Add references to TIBCO.Rendezvous and ensure that TIBCO.Rendezvous.netmodule resides in the same folder as TIBCO.Rendezvous (just in case you&#8217;re not referencing the TIB RV installation itself<\/li>\n<li>For this simple example we&#8217;ll hard code a few variables\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nstring server = arguments&#x5B;\"server\"];\r\nstring network = arguments&#x5B;\"network\"];\r\nstring daemon = arguments&#x5B;\"daemon\"];\r\n<\/pre>\n<\/li>\n<li>\nNext we need to open the Rendezvous environment using<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nTIBCO.Rendezvous.Environment.Open();\r\n<\/pre>\n<p>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&#8217;ll just assume it&#8217;s all in a try..catch block\n<\/li>\n<li>\nWe now need to create the transport <\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nTransport transport = new NetTransport(service, network, daemon);\r\n<\/pre>\n<\/li>\n<li>\nNow it&#8217;s time to create the message. The subject is set to &#8220;myapp.mysubject&#8221; and we add some data to a new field we&#8217;ve created named &#8220;Data&#8221;<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nMessage message = new Message { SendSubject = \"myapp.mysubject\" };\r\nmessage.AddField(\"Data\", \"Some Data\");\r\n<\/pre>\n<\/li>\n<li>\nTo send the message is simply a case of <\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\ntransport.Send(message);\r\n<\/pre>\n<\/li>\n<li>\nFinally when we&#8217;ve finished with RV we need to close the environment with<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nTIBCO.Rendezvous.Environment.Close();\r\n<\/pre>\n<\/li>\n<\/ol>\n<p>Before we look at the full code, here&#8217;s what the listener shows us if we listen to &#8220;myapp.>&#8221;<\/p>\n<p>2013-11-21 15:58:49 (2013-11-21 15:58:49.281000000Z): subject=myapp.mysubject, message={Data=&#8221;Some Data&#8221;}<\/p>\n<p>And as promised, the full code is<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic void Process(CommandLineArguments arguments)\r\n{\r\n   string service = arguments&#x5B;\"server\"];\r\n   string network = arguments&#x5B;\"network\"];\r\n   string daemon = arguments&#x5B;\"daemon\"];\r\n\r\n   try\r\n   {\r\n      TIBCO.Rendezvous.Environment.Open();\r\n\r\n      Transport transport = new NetTransport(service, network, daemon);\r\n\r\n      Message message = new Message { SendSubject = \"myapp.mysubject\" };\r\n      message.AddField(\"Data\", \"Some Data\");\r\n      transport.Send(message);\r\n   }\r\n   catch (Exception e)\r\n   {\r\n      Console.WriteLine(e.Message + \"\\n\\n\" + e.StackTrace);\r\n   }\r\n   finally\r\n   {\r\n      TIBCO.Rendezvous.Environment.Close();\r\n   }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The previous post was on creating a minimal TIBCO RV listener. So naturally it&#8217;s time to look at creating a minimal TIBCO RV &#8220;sender&#8221;. 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[56,55],"tags":[],"class_list":["post-787","post","type-post","status-publish","format-standard","hentry","category-rv","category-tibco"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=787"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/787\/revisions"}],"predecessor-version":[{"id":8585,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/787\/revisions\/8585"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}