从 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. C语言 · 最大最小公倍数

    算法训练 最大最小公倍数   时间限制:1.0s   内存限制:256.0MB        锦囊1 使用贪心来选择. 锦囊2 当n为奇数时,答案一定是n*(n-1)*(n-2). 当n为偶数时,答案 ...

  2. 奇妙的go语言(面向对象)

    [ 声明:版权全部.欢迎转载,请勿用于商业用途.  联系信箱:feixiaoxing @163.com] 有过C++语言学习经历的朋友都知道.面向对象主要包含了三个基本特征:封装.继承和多态.封装,就 ...

  3. iOS开发小技巧--cell往左拖拽出现很多按钮的实现,仅仅适用于iOS8以后

    // 往左拖拽cell出现多个按钮的实现,仅仅适用于iOS_8.0以后 - (NSArray<UITableViewRowAction *> *)tableView:(UITableVie ...

  4. thinkphp 连接mssql 当local失效时

    <?php return array( //'配置项'=>'配置值' //'USERNAME'=>'admin', //赋值 //数据库配置信息 'DB_TYPE' => 'm ...

  5. Python之批量改变图片大小

    image_pylib模块:https://github.com/huangshiyu13/image_pylib data_engine模块:https://github.com/huangshiy ...

  6. Qt模态与非模态

    模态对话框就是指在子对话框弹出时,焦点被强行集中于该子对话框,子对话框不关闭,用户将无法操作其他的窗口.非模态相反,用户仍然可以操作其他的窗口,包括该子对话框的父对话框. 如果从线程角度来讲,模态对话 ...

  7. Onject.Instantiate实例

    该函数有两个函数原型: Object Instantiate(Object original,Vector3 position,Quaternion rotation); Onject Instant ...

  8. Surfer 高并发双核无头浏览器 (Golang语言)

    Surfer   A high level concurrency downloader. surfer是一款Go语言编写的高并发爬虫下载器,拥有surf与phantom两种下载内核. 支持固定Use ...

  9. js实现密码强度

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  10. MySQL 若干操作

    复制表结构+复制表数据 mysql> create table t3 like t1; mysql> insert into t3 select * from t1; mysql索引 1. ...