首页 > 其他分享 >TIBCO.Rendezvous简单的发消息的过程

TIBCO.Rendezvous简单的发消息的过程

时间:2023-11-23 16:13:07浏览次数:17  
标签:Console Environment arguments TIBCO Rendezvous message 发消息

C#代码实现发消息的过程.

首先需要安装,添加引用,

using TIBCO.Rendezvous;

然后其实就是简单4个步骤 ,即可把讯息发出去;

开启环境 ->实例化NetTransport ->生成需要发送的 Message->transport.Send(msg); 最后关闭环境;

 1             //开启环境;
 2             TIBCO.Rendezvous.Environment.Open();
 3             // 实例化一个用来发送讯息的NetTransport ;
 4             NetTransport transport = new NetTransport(service, network, daemon);
 5             // 实例化消息;
 6             Message msg = new Message();
 7             //消息主题;
 8             msg.SendSubject = subject;
 9             //添加消息内容字段
10             msg.AddField(name1, value1);
11             msg.AddField(name2, value2);
12             // 发送出去
13             transport.Send(msg);
14             //关闭环境
15             TIBCO.Rendezvous.Environment.Close();

下面给出官网的DEMO 文档代码 

  1 /// Copyright (c) 1998-$Date: 2013-12-20 07:48:17 -0800 (Fri, 20 Dec 2013) $ TIBCO Software Inc.
  2 /// All rights reserved.
  3 /// TIB/Rendezvous is protected under US Patent No. 5,187,787.
  4 /// For more information, please contact:
  5 /// TIBCO Software Inc., Palo Alto, California, USA
  6 using System;
  7 using System.Net;
  8 using TIBCO.Rendezvous;
  9  
 10 namespace TIBCO.Rendezvous.Examples
 11 {
 12     /// <summary>
 13     ///  RendezvousSender - sample Rendezvous message publisher.
 14     ///  This program publishes one or more string messages on a specified
 15     ///  subject.  Both the subject and the message(s) must be supplied as
 16     ///  command parameters.  Message(s) with embedded spaces should be quoted.
 17     ///  A field named "DATA" will be created to hold the string in each
 18     ///  message.
 19     ///  
 20     ///  Optionally the user may specify communication parameters for 
 21     ///  NetTransport constructor. If none are specified the following 
 22     ///  defaults are used:
 23     ///  
 24     ///  service     "rendezvous" or "7500/udp"
 25     ///  network     the result of gethostname
 26     ///  daemon      "tcp:7500"
 27     ///     
 28     ///  Normally a listener such as tibrvlisten should be started first.
 29     ///  
 30     ///  Examples:
 31     ///  
 32     ///  Publish two messages on subject a.b.c and default parameters:
 33     ///  RendezvousSender a.b.c "This is my first message" "This is my second message"
 34     ///  
 35     ///  Publish a message on subject a.b.c using port 7566:
 36     ///  RendezvousSender -service 7566 a.b.c message
 37     /// </summary>
 38     class SenderApplication
 39     {
 40         static string service = null;
 41         static string network = null;
 42         static string daemon = null;
 43         static int iterations = 1;
 44  
 45         const String FIELD_NAME = "DATA";
 46  
 47         /// <summary>
 48         /// The main entry point for the application.
 49         /// </summary>
 50         [MTAThread]
 51         static void Main(string[] arguments)
 52         {
 53             int argumentsCount = InitializeParameters(arguments);
 54  
 55             if (argumentsCount > (arguments.Length - 2))
 56             {
 57                 Usage();
 58             }
 59  
 60             try
 61             {
 62                 /* Create internal TIB/Rendezvous machinery */
 63                 if (TIBCO.Rendezvous.Environment.IsIPM())
 64                 {
 65                     /*
 66                      * Prior to using the Rendezvous IPM library please read the appropriate
 67                      * sections of the user guide to determine if IPM is the correct choice
 68                      * for your application; it is likely not.
 69                      *
 70                      * To use the shared Rendezvous IPM library in .NET on Windows,
 71                      * first make sure it is located in your system path before the standard
 72                      * Rendezvous library.
 73                      *
 74                      * The IPM shared library can be found in %TIBRV_HOME%\bin\ipm.
 75                      *
 76                      * The IPM static library can be found in %TIBRV_HOME%\lib\ipm.
 77                      *
 78                      * To configure IPM you can do one of the following:
 79                      *
 80                      * 1) Nothing, and accept the default IPM RV parameter values.
 81                      *
 82                      * 2) Place a file named "tibrvipm.cfg" in your PATH, and have
 83                      * IPM automatically read in configuration values.
 84                      *
 85                      * 3) Call Environment.SetRVParameters, prior to Environment.Open:
 86                      *
 87                      *   string[] parameters =
 88                      *    new string[] {"-reliability", "3", "-reuse-port", "30000"};
 89                      *   Environment.SetRVParameters(parameters);
 90                      *   Environment.Open();
 91                      *
 92                      * 4) Call Environment.Open(string pathname), and have IPM read
 93                      * in the configuration values:
 94                      *
 95                      *   Environment.Open(".\\tibrvipm.cfg");
 96                      *
 97                      * An example configuration file, "tibrvipm.cfg", can be found in the
 98                      * "%TIBRV_HOME%\examples\IPM" directory of the Rendezvous installation.
 99                      *
100                      */
101                     TIBCO.Rendezvous.Environment.Open(".\\tibrvipm.cfg");
102                 }
103                 else
104                 {
105                     TIBCO.Rendezvous.Environment.Open();
106                 }
107             }
108             catch(RendezvousException exception)
109             {
110                 Console.Error.WriteLine("Failed to open Rendezvous Environment: {0}", exception.Message);
111                 Console.Error.WriteLine(exception.StackTrace);
112                 System.Environment.Exit(1);
113             }
114  
115             // Create Network transport
116             Transport transport = null;
117             try
118             {
119                 transport = new NetTransport(service, network, daemon);
120             }
121             catch (RendezvousException exception)
122             {
123                 Console.Error.WriteLine("Failed to create NetTransport:");
124                 Console.Error.WriteLine(exception.StackTrace);
125                 System.Environment.Exit(1);
126             }
127             
128             // Create the message
129             Message message = new Message();
130  
131             // Set send subject into the message
132             try
133             {
134                 message.SendSubject = arguments[argumentsCount++];
135             }
136             catch (RendezvousException exception) 
137             {
138                 Console.Error.WriteLine("Failed to set send subject:");
139                 Console.Error.WriteLine(exception.StackTrace);
140                 System.Environment.Exit(1);
141             }
142  
143             try
144             {
145                 // Send one message for each parameter
146                 while (argumentsCount < arguments.Length)
147                 {
148                     Console.Out.WriteLine("Publishing: subject={0} \"{1}\"",
149                         message.SendSubject,
150                         arguments[argumentsCount]);
151                     message.AddField(FIELD_NAME, arguments[argumentsCount], 0);
152                     for (int i = 0; i < SenderApplication.iterations; i++)
153                     {
154                         transport.Send(message);
155                     }
156                     argumentsCount++;
157                 }
158             }
159             catch (RendezvousException exception)
160             {
161                 Console.Error.WriteLine("Error sending a message:");
162                 Console.Error.WriteLine(exception.StackTrace);
163                 System.Environment.Exit(1);
164             }
165  
166             // Close Environment, it will cleanup all underlying memory, destroy
167             // transport and guarantee delivery.
168             try
169             {
170                 TIBCO.Rendezvous.Environment.Close();
171             }
172             catch(RendezvousException exception)
173             {                
174                 Console.Error.WriteLine("Exception dispatching default queue:");
175                 Console.Error.WriteLine(exception.StackTrace);
176                 System.Environment.Exit(1);
177             }
178         }
179         
180         static void Usage()
181         {
182             Console.Out.Write("Usage: RendezvousSender [-service service] [-network network]");
183             Console.Out.Write("                        [-daemon daemon] <subject> <messages>");
184             System.Environment.Exit(1);
185         }
186  
187         static int InitializeParameters(string[] arguments)
188         {
189             int i = 0;
190             while(i < arguments.Length - 1 && arguments[i].StartsWith("-"))
191             {
192                 if (arguments[i].Equals("-service"))
193                 {
194                     service = arguments[i+1];
195                     i += 2;
196                 }
197                 else
198                     if (arguments[i].Equals("-network"))
199                 {
200                     network = arguments[i+1];
201                     i += 2;
202                 }
203                 else
204                     if (arguments[i].Equals("-daemon"))
205                 {
206                     daemon = arguments[i+1];
207                     i += 2;
208                 }
209                 else
210                     if (arguments[i].Equals("-iterations"))
211                 {
212                     iterations = Int32.Parse(arguments[i+1]);
213                     i += 2;
214                 }
215                 else
216                     Usage();
217             }
218             return i;
219         }
220     }    
221 }

 

标签:Console,Environment,arguments,TIBCO,Rendezvous,message,发消息
From: https://www.cnblogs.com/liuqifeng/p/17851781.html

相关文章

  • 抖音主播私信脚本,给直播间的主播发消息,按键精灵脚本开源
    这个脚本运行后会给正在直播的主播自动发送话术消息,也是用按键精灵写的,我自己测试运行没有任何问题,下面是UI和代码。UI界面:  界面代码:=================================================界面1:{请在下面设置话术:{输入框:{名称:"输入框1",提示内容:"提示用户应该......
  • javascript postMessage给子页面发消息
    发送消息页面<!DOCTYPEhtml><html><head><title>demo</title><metacharset="utf-8"/><script>varchildwinconstchildname="popup"functionopenChild(){......
  • [swin-trans]分布式训练的debug:ValueError: Error initializing torch.distributed us
    在用torch.distributed.init_process_group(backend='nccl',init_method='env://',world_size=world_size,rank=rank)时,出现1、ValueError:Errorinitializingtorch.distributedusingenv://rendezvous:environmentvariableMASTER_ADDRexpected,b......
  • 微信使用python定时主动群发消息
    目前市面上的微信营销软件,绝大部分是模拟登录或者进程hook外挂形式,属于违规使用微信的范畴,容易被微信官方封号。经过思考后,我觉得利用python自动化UI点击,鼠标键盘操作,是符合真人使用微信的习惯的,被封的风险最低。因为必须是UI自动化,所以我们使用windows系统,并且结合微信电脑版来实......
  • P3533 [POI2012] RAN-Rendezvous 题解
    P3533[POI2012]RAN-Rendezvous题目大意:给定外向树森林,每次给定两个起始点,求两个点沿边移动最少步数相遇。\(n\)个点,\(n\)条边,并且每个点有唯一的出边,显然构成了多棵基环树,对于每个基环树分别处理:找出环上的点,因为要求支持求出任意两点距离,前缀和一下即可。对于询问,如果在两......
  • Rendezvous hashing算法介绍
    RendezvoushashingRendezvoushashing用于解决分布式系统中的分布式哈希问题,该问题包括三部分:Keys:数据或负载的唯一标识Values:消耗资源的数据或负载Servers:管理数据或负载的实体例如,在一个分布式系统中,key可能是一个文件名,value是文件数据,servers是连接网络的数据服务器,......
  • SpringBoot中使用Netty开发WebSocket服务-netty-websocket-spring-boot-starter开源项
    场景SpringBoot+Vue整合WebSocket实现前后端消息推送:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/114392573SpringCloud(若依微服务版为例)集成WebSocket实现前后端的消息推送:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/114480731若依前后......
  • SpringBoot集成kafka收发消息——传递消息为对象
    目前springboot整合后的kafka,因为序列化器是StringSerializer,这个时候如果需要传递对象可以有两种方式方式一:可以自定义序列化器,对象类型众多,这种方式通用性不强。方式二:可以把要传递的对象进行转json字符串,接收消息后再转为对象即可,本项目采用这种方式JSON.toJSONString(user)......
  • Netty-TCP 04.发消息
    本文是使用Netty开发一个简单的TCP通讯(聊天)应用程序的第【4】部分,主要测试客户端和服务端的通讯。服务端下面是服务端测试代码:/***@authormichong*/publicclassTCPServer{publicstaticvoidmain(String[]args){TCPServerBootstrapbootstrap=ne......
  • 怎么将C#通过发消息传递给指定C++窗口
    C#发送方//引入Interop库usingSystem.Runtime.InteropServices;//定义SendMessageAPI[DllImport("user32.dll",CharSet=CharSet.Auto,SetLastError=false)]staticexternIntPtrSendMessage(IntPtrhWnd,uintMsg,IntPtrwParam,IntPtrlParam);//......