从 C# 客户端连接 Tibco EMS

下面例子简要介绍 C# 客户端怎样使用 TIBCO.EMS.dll 来连接 EMS 服务器.

using System;
using System.Diagnostics;
using System.Threading;
using TIBCO.EMS; namespace TestEMS
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Test started");
new Program().Run();
Console.ReadLine();
} private void Run()
{
StartEMSServer();
CreateEMSServerTopicPublisher();
CreateClientTopicSubscriber("Owner LIKE '%Rich Newman%'"); // Pass "" for no message selector
EMSServerPublishThisMessage("Hello World", "Owner", "Rich Newman");
} #region EMS Server
private const string tibcoEMSPath = @"C:\tibco\ems\5.0\bin\";
private readonly string tibcoEMSExecutable = tibcoEMSPath + "tibemsd.exe";
private Process tibcoEMSProcess;
public void StartEMSServer()
{
tibcoEMSProcess = new Process();
ProcessStartInfo processStartInfo = new ProcessStartInfo(tibcoEMSExecutable);
tibcoEMSProcess.StartInfo = processStartInfo;
processStartInfo.WorkingDirectory = tibcoEMSPath;
bool started = tibcoEMSProcess.Start();
Thread.Sleep(500);
} TopicConnection publisherConnection;
TopicSession publisherSession;
TopicPublisher emsServerPublisher;
private void CreateEMSServerTopicPublisher()
{
TopicConnectionFactory factory = new TIBCO.EMS.TopicConnectionFactory("localhost");
publisherConnection = factory.CreateTopicConnection("", ""); // Username, password
publisherSession = publisherConnection.CreateTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic generalTopic = publisherSession.CreateTopic("GeneralTopic");
emsServerPublisher = publisherSession.CreatePublisher(generalTopic); publisherConnection.Start();
} internal void EMSServerPublishThisMessage(string message, string propertyName, string propertyValue)
{
TextMessage textMessage = publisherSession.CreateTextMessage();
textMessage.Text = message;
textMessage.SetStringProperty(propertyName, propertyValue);
emsServerPublisher.Publish(textMessage);
Console.WriteLine("EMS Publisher published message: " + message);
} #endregion #region EMS Client
TopicConnection subscriberConnection;
TopicSession subscriberSession;
private void CreateClientTopicSubscriber(string messageSelector)
{
TopicConnectionFactory factory = new TIBCO.EMS.TopicConnectionFactory("localhost");
subscriberConnection = factory.CreateTopicConnection("", ""); // Username, password
subscriberConnection.Start();
subscriberSession = subscriberConnection.CreateTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic clientTopic = subscriberSession.CreateTopic("GeneralTopic");
TopicSubscriber clientTopicSubscriber = subscriberSession.CreateSubscriber(clientTopic, messageSelector, true);
clientTopicSubscriber.MessageHandler += new EMSMessageHandler(test_MessageHandler);
} void test_MessageHandler(object sender, EMSMessageEventArgs args)
{
Console.WriteLine("EMS Client received message: " + args.Message.ToString());
} #endregion
}
}

C# EMS Client的更多相关文章

  1. tibco EMS 8.2.0安装

    安装环境 序号 项目 值 1 OS版本 Red Hat Enterprise Linux Server release 7.1 (Maipo) 2 内核版本 3.10.0-229.el7.x86_64 ...

  2. 轻量级远程调用框架-Hessian学习笔记-Demo实现

    Hessian是一个轻量级的remoting onhttp工具,使用简单的方法提供了RMI的功能. 相比WebService,Hessian更简单.快捷.采用的是二进制RPC协议,因为采用的是二进制协 ...

  3. Android简单实现Socket通信,client连接server后,server向client发送文字数据

    案例实现的是简单的Socket通信,当client(Androidclient)连接到指定server以后,server向client发送一句话文字信息(你能够拓展其他的了) 先看一下服务端程序的实现 ...

  4. vmware里面的名词 vSphere、vCenter Server、ESXI、vSphere Client

    vmware里面的名词 vSphere.vCenter Server.ESXI.vSphere Client vSphere.vCenter Server.ESXI.vSphere Client VS ...

  5. Apache2.4:AH01630 client denied by server configuration

    问题说明:Apache服务总共有4个,是为了防止单点故障和负载均衡,负载均衡控制由局方的F5提供. 访问的内容在NAS存储上,现象是直接访问每个apache的服务内容都是没有问题,但是从负载地址过来的 ...

  6. [异常解决] windows用SSH和linux同步文件&linux开启SSH&ssh client 报 algorithm negotiation failed的解决方法之一

    1.安装.配置与启动 SSH分客户端openssh-client和openssh-server 如果你只是想登陆别的机器的SSH只需要安装openssh-client(ubuntu有默认安装,如果没有 ...

  7. xamarin IOS 报错处理: an error occurred on client Build420719 while

    xamarin IOS 开发时如果报错如下: an error occurred on client Build420719 while...... 出现如下问题时,可能是1.丢失文件2.没有包括在项 ...

  8. ASP.NET OAuth:access token的加密解密,client secret与refresh token的生成

    在 ASP.NET OWIN OAuth(Microsoft.Owin.Security.OAuth)中,access token 的默认加密方法是: 1) System.Security.Crypt ...

  9. 在ASP.NET中基于Owin OAuth使用Client Credentials Grant授权发放Token

    OAuth真是一个复杂的东东,即使你把OAuth规范倒背如流,在具体实现时也会无从下手.因此,Microsoft.Owin.Security.OAuth应运而生(它的实现代码在Katana项目中),帮 ...

随机推荐

  1. 枚举类转成json

    import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; /** * portlet类别枚举类 */ ...

  2. java资料——哈希表(散列表)(转)

    哈希表       散列表(Hash table,也叫哈希表),是根据关键码值(Key value)而直接进行访问的数据结构.也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度. ...

  3. BusyBox inittab配置

    inittab第一行指定初始化脚本,开启所有应用程序,必须有. ::sysinit:/etc/init.d/rcS 在第一行执行完后,执行剩余行命令,此终端要接受命令交互需开启sh. ::askfir ...

  4. m个苹果放在n个盘子里面有多少种放法?(动态规划)

    m个苹果放在n个盘子里面有多少种放法?(动态规划) 实现代码如下: #include <iostream> using namespace std; int s(int m ,int n) ...

  5. Ubuntu14.04使用DEB安装Mysql5.7

    下载deb-bundle包 1.mysql下载页面 2.解压 安装(注意安装顺序)          安装顺序如下:           1.mysql-common_5.7.10-1ubuntu14 ...

  6. 【3C认证】安防产品3C认证

    安防产品3C认证作为3C认证的一部分.安防产品即:防范的手段达到或实现安全的目的的设备或器材. 依据<中华人民共和国产品质量法>.<中华人民共和国标准化法>.<中华人民共 ...

  7. Firefox 在LR录制过程中添加例外的问题解决方法

    用lr调火狐打开网页  会报证书安全问题 证书安全提示目的是告诉你这个服务器使用的证书可能不安全,要不要信任,你自己决定,不信任就不能访问.为什么会报证书安全,因为浏览器没添加该证书.或者由于性能工具 ...

  8. C语言 常用的宏定义

    __FILE__ :宏在预编译时会替换成当前的源文件名 __LINE__:宏在预编译时会替换成当前的行号 __FUNCTION__:宏在预编译时会替换成当前的函数名称 //宏__VA_ARGS__的用 ...

  9. 关于Cocos2d-x中对其他某个类的某个属性的获得

    类A要获得类B中的某个属性,可以是节点属性 方法一 1.先在B类中定义一个_edge的节点属性(可以在B类中进行各种对_edge的操作),然后写一个方法Node* GameController::ge ...

  10. Spring Boot 官方文档学习(二)特点

    一.SpringApplication banner,就是启动时输出的信息,可以在classpath下添加 banner.txt,或者设置 banner.location 来指向特定的文件.(默认编码 ...