Connecting to MQSeries with .NET

By connecting to MQSeries withing a .NET application, first it has to be done is to install MQ Series client at the machine which will host the application.
To do that, you can obtain for example the trial
version of WebSphere MQ. During installation first the prerequisites are
checked. Unfortunately if you try to install the package at Windows
Vista, no wonder, it will just fail, because the operative system is
currently not supported by the setup. The good thing is that this
requirement just can be ignored. Clearly that means, just install all
other prerequisites and proceed with installation.

If you
installed the Web Sphere at the local machine or somewhere in the
windows environment with active directory infrastructure, there is a
group named "MQM". The windows user who is running your .NET application
has to be member of this group in order to be able to connect to MQ. In
that case following code can be used to establish the connection and to
put one simple message in the queue:


[TestMethod]
        [Description("Changes the status of one single event."), Owner("ddobric")]
        public void MQ()
        {
            MQQueueManager queueManager = new MQQueueManager("QM_testmgr", "mychannel", "192.168.1.64");
            MQQueue queue = queueManager.AccessQueue("default", MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
            MQMessage queueMessage = new MQMessage();

queueMessage.Format = MQC.MQFMT_STRING;
            queueMessage.MessageId = new byte[] { 0x01, 0x02, 0x03, 0x04};
            queueMessage.WriteString("Hello World");

MQPutMessageOptions queuePutMessageOptions = new MQPutMessageOptions();
            queue.Put(queueMessage, queuePutMessageOptions);

}

This
code connects to the MQ manager "QM_testmgr" by using of channel
"mychannel" hostet at the specified IP address. After executing you can
see the message in the queue "default".
Assume you want now to
connect to some remote machine. If you use this code the connection to
the queueManager will fail with reason code 2035 = Not Authorized. To
avoid this problem the MCA of the remote channel
has to be
explicitly set. To do that, open the MQ Explorer go to channel
properties and open the tab MCA. Then enter the name of the user who is
authorized to connect. In the example bellow, I used the user "mqm".

Now the code in the .NET application has to be slightly changed as shown in the next example:


[TestMethod]
        [Description("Changes the status of one single event."), Owner("ddobric")]
        public void MQ()
        {
            Hashtable props = new Hashtable();
            props.Add(MQC.HOST_NAME_PROPERTY, "sopmqseries");
            props.Add(MQC.CHANNEL_PROPERTY, m_ChannelName);
            props.Add(MQC.USER_ID_PROPERTY, "mqm");
            props.Add( MQC.PASSWORD_PROPERTY, "enter anything here." );

MQQueueManager queueManager = new MQQueueManager(m_QueueManager, props);

MQQueue queue = queueManager.AccessQueue("default",
            MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
            MQMessage queueMessage = new MQMessage();

queueMessage.Format = MQC.MQFMT_STRING;
            queueMessage.MessageId = new byte[] { 0x01, 0x02, 0x03, 0x04};
            queueMessage.WriteString("Hello World");

MQPutMessageOptions queuePutMessageOptions = new MQPutMessageOptions();
            queue.Put(queueMessage, queuePutMessageOptions);

}

At
this point is important, that specified username "mqm" has to match the
name set in the MCA-tab. Additionally it is interesting, that the
password does not have to match user‘s password, but it has to be
specified as property.
If password property is not specified at all, the initialization will crash with a "null reference error".

Last
but not least. If you do not want to specify the username in your code,
means you would like to use the first code example, there also one a
little confusing possibility. Create some other user and put in the MQM
group. The name of this user should be the same as the name of user who
will run the .NET application. In this case if the name of interactive
user (who is running the application) matches the name of the user
member of MQM group at the remote system (this does not have to be
necessarily windows system) you will not need the provide credential
properties (MQC.USER_ID_PROPERTY and MQC.PASSWORD_PROPERTY) and MCA name may be empty.

By troubleshooting following very useful link contains the list of all reason codes.

时间: 2024-10-26 23:17:32

Connecting to MQSeries with .NET的相关文章

主从同步出现一下错误:Slave_IO_Running: Connecting

主从同步出现一下错误: Slave_IO_Running: Connecting Slave_SQL_Running: Yes 解决方法: 导致lave_IO_Running 为connecting 的原因主要有以下 3 个方面: 1.网络不通 2.密码不对 3.pos不对 我敢肯定的并且排除的两个原因 1. 网络原因:在从库上拷贝主库上的备份文件的时候并没有出现任何的错误,因此可以排除. 2. POS 不对:这个我也可以排除,因为在主库上 show maste status 时我记录过了 PO

hdfs启动后进入safe mode,Problem connecting to server

原创文章:http://blog.csdn.net/renfengjun/article/details/25320043 DN中日志如下: 2017-06-17 06:35:59,242 WARN org.apache.hadoop.hdfs.server.datanode.DataNode: Problem connecting to server: node1/192.168.1.128:90002017-06-17 06:36:05,246 INFO org.apache.hadoop.

nginx反向代理tomcat提示13 permission denied while connecting to upstream

nginx反向代理tomcat提示13 permission denied while connecting to upstream,网上很多都是说13 permission denied while reading to upstream,这是两个完全不同的错误,我遇到的如下截图: 查看selinux日志发现错误: 后来发现是selinux的问题,于是先关掉selinux:setenforce 0:然后再访问果然好使. 于是启用selinux,再执行下面的命令,修改selinux的值: set

线上nginx的一次“no live upstreams while connecting to upstream ”分析

先描述一下环境,前段的负载均衡转发给nginx,nginx再转发给后端的应用服务器. nginx配置文件如下: upstream ads { server ap1:8888 max_fails=1 fail_timeout=60s; server ap2:8888 max_fails=1 fail_timeout=60s; } 出现的现象是: 日志里面每隔一两分钟就会记录一条类似 *379803415 no live upstreams while connecting to upstream 

hadoop 开始时间datanode一个错误 Problem connecting to server

刚刚配置hadoop,namenode常开,但datanode但保留了错误.但不启动: 2014-05-04 10:43:33,970 WARNorg.apache.hadoop.hdfs.server.datanode.DataNode: Problem connecting to server:hadoop1/192.168.10.22:9000 2014-05-04 10:43:55,009 INFOorg.apache.hadoop.ipc.Client: Retrying connec

Qt5官方demo解析集16——Chapter 2: Connecting to C++ Methods and Signals

本系列所有文章可以在这里查看http://blog.csdn.net/cloud_castle/article/category/2123873 接上文Qt5官方demo解析集15--Chapter 1: Creating a New Type 在上篇博文我们了解到如何在C++代码中将一个C++类注册为一个QML类型,并供QML文件使用.接下来这个Demo中进一步向这个PieChart中添加信号和方法供QML使用. 在项目上没有什么改变,我们直接来看代码PieChart.h: #ifndef P

ubuntu 更显列表 [Connecting to archive.ubuntu.com (2001:67c:1360:8001::21)] 超时的解决方法

问题描述: 在使用apt-get update 时更行列表,显示[Connecting to archive.ubuntu.com (2001:67c:1360:8001::21)]超时 分析: 我已更改为ubuntu的阿里云,不应该出现访问不了的情况,通过搜索,得知原因如下ubuntu默认走ipv6,但是我更改的阿里源应该不支持ipv6. 解决方法: 打开/etc/gai.conf(地址信息的配置文件),找到#precedence ::ffff:0:0/96  100, 将"#" 去

nodejs:注册登录session出错以及连接Mongodb数据库时Error connecting to database解决方案

(1)nodejs:注册登录session出错 解决办法: 在app.js 中将var MongoStore =  require(connect-mongo')改为var MongoStore =  require(connect-mongo')(express) 即可: (2)连接Mongodb数据库时Error connecting to database解决方案 这种情况下是自己的mongodb数据库没有装好 解决办法: a.在官网上下载安装数据库 b.在mongodb文件夹里面新建文件

postgreSQL远程连接出现:Error connecting to server :致命错误 SSL关闭的pg_hba.conf记录

异常截图: 解决方案: [[email protected] ~]# vi /var/lib/pgsql/data/pg_hba.conf # TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all ident # IPv4 local connections: host all all 127.0.0.1/32 ident hos