从 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. 核心交换机各项配置 Vlan划分、互访、ACL管控、链路聚合等

    #!Software Version V200R001C00SPC300sysname IT_ServerRoom  #交换机名称##vlan batch 10 20 30 40 50 60 70 8 ...

  2. kettle7.1无法从Mongo中读取数据

    今天使用kettle读取mongo数据库时,刚开始一直无法读取数据: 在配置项中偶然选择了一个nearest然后成功了,麻蛋. 然后百度查询了下Read Reference是干嘛的,原来是读取源的模式 ...

  3. 【springmvc笔记】第二课 环境搭建和第一个springmvc例子

    1. 开发工具准备 eclipse + jdk1.7 spring-framework-4.3.9.RELEASE 2. 新建Dynamic Web Project项目,命名为springmvc. 3 ...

  4. 聊聊Python中的多进程和多线程

    今天,想谈一下Python中的进程和线程. 最近在学习Django的时候,涉及到了多进程和多线程的知识点,所以想着一下把Python中的这块知识进行总结,所以系统地学习了一遍,将知识梳理如下. 1. ...

  5. 測试Service

    <strong><span style="font-size:18px;">自己定义Service:</span></strong> ...

  6. ftp 长传报错553 可能是选的目录不对

    ftp> put /root/20180711tmp.txt /cc.txt local: /root/20180711tmp.txt remote: /cc.txt 200 PORT comm ...

  7. ASP.NET MVC 使用 Datatables (2)

    在服务器端实现分页,排序,获取当前页面数据 在上篇的基础上进行改造(datatables的客户端实现) 1.修改View页面代码如下: <div class="row"> ...

  8. javascript时钟代码 DEMO-002

    转载自:http://www.cnblogs.com/Mygirl/archive/2012/03/30/2425832.html 正常时间显示 复制代码 <SCRIPT language=ja ...

  9. RequireJS使用小结1——for Effective JavaScript Module Loading

    1. require和define的区别 The require() function is used to run immediate functionalities, while define() ...

  10. Node.js进程通信模块child_process

    前言 Node.js是一种单线程的编程模型,对Node.js的赞美和诟病的也都是因为它的单线程模型,所有的任务都在一个线程中完成(I/O等例外).单线程模型,不仅让代码非常简洁,更是直接避免了线程调度 ...