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

 

有关TIBCO RV的介绍资料几乎是一搜一大堆,但是相关的C#代码基本上还是空白没有的.

对于新手来说,需要使用TIBCO RV通常是比较困难的 ,需要学习一大堆的相关资料.

这里简单写一下C#代码实现发消息的过程.

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

using TIBCO.Rendezvous;

 

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

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

 

            //开启环境;
            TIBCO.Rendezvous.Environment.Open();
            // 实例化一个用来发送讯息的NetTransport ;
            NetTransport transport = new NetTransport(service, network, daemon);
            // 实例化消息;
            Message msg = new Message();
            //消息主题;
            msg.SendSubject = subject;
            //添加消息内容字段
            msg.AddField(name1, value1);
            msg.AddField(name2, value2);
            // 发送出去
            transport.Send(msg);
            //关闭环境
            TIBCO.Rendezvous.Environment.Close();

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

相信这份文档会对初次接触TIBCO.Rendezvous 的开发者极大的帮助.

/// Copyright (c) 1998-$Date: 2013-12-20 07:48:17 -0800 (Fri, 20 Dec 2013) $ TIBCO Software Inc.
/// All rights reserved.
/// TIB/Rendezvous is protected under US Patent No. 5,187,787.
/// For more information, please contact:
/// TIBCO Software Inc., Palo Alto, California, USA
using System;
using System.Net;
using TIBCO.Rendezvous;

namespace TIBCO.Rendezvous.Examples
{
	/// <summary>
	///  RendezvousSender - sample Rendezvous message publisher.
	///  This program publishes one or more string messages on a specified
	///  subject.  Both the subject and the message(s) must be supplied as
	///  command parameters.  Message(s) with embedded spaces should be quoted.
	///  A field named "DATA" will be created to hold the string in each
	///  message.
	///  
	///  Optionally the user may specify communication parameters for 
	///  NetTransport constructor. If none are specified the following 
	///  defaults are used:
	///  
	///  service     "rendezvous" or "7500/udp"
	///  network     the result of gethostname
	///  daemon      "tcp:7500"
	///	 
	///  Normally a listener such as tibrvlisten should be started first.
	///  
	///  Examples:
	///  
	///  Publish two messages on subject a.b.c and default parameters:
	///  RendezvousSender a.b.c "This is my first message" "This is my second message"
	///  
	///  Publish a message on subject a.b.c using port 7566:
	///  RendezvousSender -service 7566 a.b.c message
	/// </summary>
	class SenderApplication
	{
		static string service = null;
		static string network = null;
		static string daemon = null;
		static int iterations = 1;

		const String FIELD_NAME = "DATA";

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[MTAThread]
		static void Main(string[] arguments)
		{
			int argumentsCount = InitializeParameters(arguments);

			if (argumentsCount > (arguments.Length - 2))
			{
				Usage();
			}

			try
			{
				/* Create internal TIB/Rendezvous machinery */
				if (TIBCO.Rendezvous.Environment.IsIPM())
				{
					/*
					 * Prior to using the Rendezvous IPM library please read the appropriate
					 * sections of the user guide to determine if IPM is the correct choice
					 * for your application; it is likely not.
					 *
					 * To use the shared Rendezvous IPM library in .NET on Windows,
					 * first make sure it is located in your system path before the standard
					 * Rendezvous library.
					 *
					 * The IPM shared library can be found in %TIBRV_HOME%\bin\ipm.
					 *
					 * The IPM static library can be found in %TIBRV_HOME%\lib\ipm.
					 *
					 * To configure IPM you can do one of the following:
					 *
					 * 1) Nothing, and accept the default IPM RV parameter values.
					 *
					 * 2) Place a file named "tibrvipm.cfg" in your PATH, and have
					 * IPM automatically read in configuration values.
					 *
					 * 3) Call Environment.SetRVParameters, prior to Environment.Open:
					 *
					 *   string[] parameters =
					 *	new string[] {"-reliability", "3", "-reuse-port", "30000"};
					 *   Environment.SetRVParameters(parameters);
					 *   Environment.Open();
					 *
					 * 4) Call Environment.Open(string pathname), and have IPM read
					 * in the configuration values:
					 *
					 *   Environment.Open(".\\tibrvipm.cfg");
					 *
					 * An example configuration file, "tibrvipm.cfg", can be found in the
					 * "%TIBRV_HOME%\examples\IPM" directory of the Rendezvous installation.
					 *
					 */
					TIBCO.Rendezvous.Environment.Open(".\\tibrvipm.cfg");
				}
				else
				{
					TIBCO.Rendezvous.Environment.Open();
				}
			}
			catch(RendezvousException exception)
			{
				Console.Error.WriteLine("Failed to open Rendezvous Environment: {0}", exception.Message);
				Console.Error.WriteLine(exception.StackTrace);
				System.Environment.Exit(1);
			}

			// Create Network transport
			Transport transport = null;
			try
			{
				transport = new NetTransport(service, network, daemon);
			}
			catch (RendezvousException exception)
			{
				Console.Error.WriteLine("Failed to create NetTransport:");
				Console.Error.WriteLine(exception.StackTrace);
				System.Environment.Exit(1);
			}
			
			// Create the message
			Message message = new Message();

			// Set send subject into the message
			try
			{
				message.SendSubject = arguments[argumentsCount++];
			}
			catch (RendezvousException exception) 
			{
				Console.Error.WriteLine("Failed to set send subject:");
				Console.Error.WriteLine(exception.StackTrace);
				System.Environment.Exit(1);
			}

			try
			{
				// Send one message for each parameter
				while (argumentsCount < arguments.Length)
				{
					Console.Out.WriteLine("Publishing: subject={0} \"{1}\"",
						message.SendSubject,
						arguments[argumentsCount]);
					message.AddField(FIELD_NAME, arguments[argumentsCount], 0);
					for (int i = 0; i < SenderApplication.iterations; i++)
					{
						transport.Send(message);
					}
					argumentsCount++;
				}
			}
			catch (RendezvousException exception)
			{
				Console.Error.WriteLine("Error sending a message:");
				Console.Error.WriteLine(exception.StackTrace);
				System.Environment.Exit(1);
			}

			// Close Environment, it will cleanup all underlying memory, destroy
			// transport and guarantee delivery.
			try
			{
				TIBCO.Rendezvous.Environment.Close();
			}
			catch(RendezvousException exception)
			{				
				Console.Error.WriteLine("Exception dispatching default queue:");
				Console.Error.WriteLine(exception.StackTrace);
				System.Environment.Exit(1);
			}
		}
		
		static void Usage()
		{
			Console.Out.Write("Usage: RendezvousSender [-service service] [-network network]");
			Console.Out.Write("                        [-daemon daemon] <subject> <messages>");
			System.Environment.Exit(1);
		}

		static int InitializeParameters(string[] arguments)
		{
			int i = 0;
			while(i < arguments.Length - 1 && arguments[i].StartsWith("-"))
			{
				if (arguments[i].Equals("-service"))
				{
					service = arguments[i+1];
					i += 2;
				}
				else
					if (arguments[i].Equals("-network"))
				{
					network = arguments[i+1];
					i += 2;
				}
				else
					if (arguments[i].Equals("-daemon"))
				{
					daemon = arguments[i+1];
					i += 2;
				}
				else
					if (arguments[i].Equals("-iterations"))
				{
					iterations = Int32.Parse(arguments[i+1]);
					i += 2;
				}
				else
					Usage();
			}
			return i;
		}
	}	
}

 

 


 

 

 

 

  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
### 回答1: com.tibco.tibrv 是一个用于集成企业应用程序的软件包。它提供了一种在不同应用程序之间实现可靠、灵活和高效通信的方式。安装这个软件包可以帮助企业更好地管理和协调各种应用程序之间的通信和数据交换。 安装 com.tibco.tibrv 包需要以下几个步骤: 1. 下载软件包:首先,需要从 TIBCO 的官方网站或其他可信来源下载 com.tibco.tibrv 安装包。确保下载的文件是最新的版本,并且与您的操作系统兼容。 2. 解压文件:在下载完成后,使用压缩软件将安装包文件解压缩到您选择的目录中。 3. 配置环境:打开解压缩后的文件夹,找到包含安装程序的文件。在执行安装程序之前,您可能需要先配置一些系统环境变量。具体的配置过程可能因操作系统而异,您可以参考安装说明文档或官方的技术支持手册。 4. 执行安装程序:运行安装程序文件,按照安装向导中的步骤进行操作。您可能需要接受许可协议,并选择安装的目标位置和其他选项。等待安装程序完成安装过程。 5. 验证安装:安装完成后,您可以打开命令行终端或其他适当的界面,输入一些测试命令来验证您的安装是否成功。您可以查看安装说明文档或官方支持文档中的示例来帮助您进行验证。 总之,通过按照以上步骤来安装 com.tibco.tibrv 包,您将能够成功获得一个用于集成企业应用程序的强大工具,以更好地管理和协调应用程序之间的通信。请注意,安装过程可能因操作系统和软件版本而有所不同,建议在进行安装之前仔细阅读相关的安装文档和技术支持材料。 ### 回答2: com.tibco.tibrv是TIBCO Rendezvous(简称TIB/RV)的一个组件,它是一个高效的、可靠的、高吞吐量的消息传递中间件。TIB/RV由TIBCO Software Inc.开发和提供支持,被广泛应用于金融、电信和制造等行业中。 要安装com.tibco.tibrv包,首先需要下载该软件包的安装程序。可以通过TIBCO官方网站或其他可信的软件下载平台获取安装程序。在下载安装程序之后,可以按照以下步骤进行安装: 1. 双击安装程序文件,启动安装程序的安装向导。 2. 根据安装向导的提示,选择安装目标文件夹和其他相关的安装选项。通常情况下,建议将软件包安装在默认的目标文件夹中,以确保正确的安装和配置。 3. 点击“下一步”按钮,开始安装过程。等待安装程序完成必要的文件复制和配置操作。 4. 安装完成后,可以选择是否启动com.tibco.tibrv的相关服务。一般情况下,建议选择启动服务,以确保软件包的正常运行。 5. 安装完成后,可以进行一些必要的配置和设置。例如,可以配置连接参数、设置日志记录级别和路径等。 6. 安装完成后,可以开始使用com.tibco.tibrv进行开发和集成。可以编写代码,并按照TIB/RV的相关文档和指南进行配置和调用。 总之,安装com.tibco.tibrv包相对简单,只需要下载安装程序,按照安装向导的提示进行配置和设置即可。安装完成后,即可开始使用该组件进行相关的开发和集成工作。 ### 回答3: com.tibco.tibrv安装包是一个用于安装TIBCO Rendezvous(TIB/RV)软件的包。TIB/RV是一种高性能的消息传递中间件,用于实现分布式系统间的通信。 com.tibco.tibrv安装包通常包含了安装TIB/RV所需的所有文件和资源。在安装前,我们需要确保系统满足TIBCO Rendezvous的要求,例如操作系统版本、内存和硬盘空间等。 安装com.tibco.tibrv通常需要执行以下步骤: 1. 下载com.tibco.tibrv安装包:我们可以从TIBCO官方网站或其他可信来源下载安装包。确保下载的是最新版本。 2. 解压安装包:将安装包解压到一个合适的位置。通常情况下,我们可以选择将解压后的文件放置在系统的某个目录下。 3. 运行安装程序:在解压后的文件中,通常会有一个安装程序。双击该程序来启动安装过程。根据安装向导的提示,逐步完成安装过程。 4. 配置参数:在安装过程中,我们可能需要配置一些参数,例如选择安装路径、指定工作目录等。根据实际需求进行配置。 5. 完成安装:安装程序会在安装完毕后给出安装成功的提示。检查是否所有的组件都已成功安装,并且没有出现任何错误。 安装完成后,我们可以开始使用TIBCO Rendezvous来实现分布式系统间的通信。根据需求,我们可以编写代码来发送和接收消息,或者使用TIBCO提供的工具来管理消息传递。 总之,com.tibco.tibrv安装包是用于安装TIB/RV软件的包,通过执行一系列步骤来完成安装。安装完成后,我们可以使用TIBCO Rendezvous实现分布式系统间的高性能通信。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值