SlideShare a Scribd company logo
6
Most read
7
Most read
10
Most read
IBM MQ And C#-Sending And Receiving Messages
Introduction:
What is IBM MQ?
IBM MQ is messaging middleware that simplifies and accelerates the integration
of diverse applications and business data across multiple platforms. It uses
message queues to facilitate the exchange of information between applications,
systems, services and files and simplify the creation and maintenance of business
applications.
Benefits of IBM MQ
 Rapid, seamless connectivity: Offers a single, robust and trusted messaging
backbone for dynamic heterogeneous environments.
 Secure, reliable message delivery: Preserves message integrity and helps minimize
risk of information loss.
 Lower cost of ownership: Reduces cost of integration and accelerates time to
deployment.
Connecting to IBM MQ from C#.
Note:This document targets only windows platform.
Prerequisites:
 We need to install MQ client in order to connect with MQ server. I am using
MQv8 Client.
 You can download the client software from this link.
 If you follow normal installation path it will create folder in this path “C:Program
FilesIBMWebSphere MQ”.
Note: after installing WMQ client on windows platform, if the folder “SSL” does
not get created under {IBM MQ Installation directory}, create “SSL” folder
manually.
 Also you need to have following connection properties.
AMQCLCHL.TAB This is also called Client channel
definition table. This binary file
contains client connection details and
it shall be used to connect to Client.
KEY.ARM This is the queue manager certificate
and it shall be used by WMQ client
while connecting to Server queue
manager.
Hostname The TCP/IP hostname of the machine
on which the WebSphere MQ server
resides.
Port Number The port to be used.
Channel The name of the channel to connect to
on the target queue manager.
MQ Queue Name  Name of the Queue
Queue Manager Name  The name of the queue manager to
which to connect.
ClientID (UserID) The ID used to identify the WebSphere
MQ client
Password The password used to verify the
identity of the WebSphere MQ Client.
Cipher Spec application can establish a connection
to a queue manager depends on the
CipherSpec specified at the server end
of the MQI channel and the
CipherSuite specified at the client end.
Cipher Suite  The name of the Cipher Suite to be
used by SSL.
Setting up MQ client
To set up MQ client follow the below steps.
1. Copy AMQCLCHL.TAB and Key.arm file to the following path:
{Path of IBM MQ Installation directory}/SSL
2. Set the below values as “System Variables”
Variable name Value
MQCHLLIB {Path of IBM MQ Installation
directory}/SSL
MQCHLTAB AMQCLCHL.TAB
MQSSLKEYR {Path of IBM MQ Installation
directory}/SSL
3. Run the command prompt in administrator mode. Create a key database of
type CMS using command
runmqckm -keydb -create -db "C:Program FilesIBMWebSphere MQSSL key.kdb" -
pw password -type cms -expire 365 -stash
Here the password is of your choice and please remember this password as this is
needed in future.
Note: you can find more details about the options in the command in this link-
http://www.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.ref.adm.doc/q083860_.htm
4. Add the self signed certificate to key database using the below command.
runmqckm -cert -add -db " C:Program FilesIBMWebSphere MQSSLkey.kdb" -pw
password -label ibmwebspheremq<userID> -file " C:Program FilesIBMWebSphere
MQSSLkey.arm" -format ascii
where
password is the password you choose in the Step 3 when creating key
database of type CMS.
In ibmwebspheremq<userID> replace <userID> with client id. this is used as an
identifier.
Note: Specify the absolute path of the key.arm file.
5. check if the certificate is added successfully using the below command.
runmqckm -cert -list -db " C:Program FilesIBMWebSphere MQSSLkey.kdb " -pw
password
The output of above command must list the certificate
ibmwebspheremq<userID>
Now as the client is configured Let’s do coding.
Note: add reference to the dll amqmdnet.dll. you can find this dll in the MQ installation
directory (C:….)
In this sample application I am storing all the queue properties in my
app.config file.
<configuration>
<appSettings>
<add key="QueueManagerName" value=""/>
<add key="QueueName" value=""/>
<add key="ChannelName" value=""/>
<add key="TransportType" value="TCP"/>
<add key="HostName" value=""/>
<add key="Port" value=""/>
<add key="UserID" value=""/>
<add key="Password" value="YourChoice"/>
<add key="SSLCipherSpec" value="TLS_RSA_WITH_DES_CBC_SHA"/>
<add key="SSLKeyRepository" value="C:Program FilesIBMWebSphere MQsslkey"/>
</appSettings>
</configuration>
And I am using an Info class to fetch these details
public class MQInfo
{
public string QueueManagerName { get; set; }
public string QueueName { get; set; }
public string ChannelName { get; set; }
public string TransportType { get; set; }
public string HostName { get; set; }
public string Port { get; set; }
public string UserID { get; set; }
public string Password { get; set; }
public string SSLCipherSpec { get; set; }
public string SSLKeyRepository { get; set; }
public MQInfo()
{
QueueManagerName = ConfigurationManager.AppSettings["QueueManagerName"];
QueueName = ConfigurationManager.AppSettings["QueueName"];
ChannelName = ConfigurationManager.AppSettings["ChannelName"];
TransportType = ConfigurationManager.AppSettings["TransportType"];
HostName = ConfigurationManager.AppSettings["HostName"];
Port = ConfigurationManager.AppSettings["Port"];
UserID = ConfigurationManager.AppSettings["UserID"];
Password = ConfigurationManager.AppSettings["Password"];
SSLCipherSpec = ConfigurationManager.AppSettings["SSLCipherSpec"];
SSLKeyRepository = ConfigurationManager.AppSettings["SSLKeyRepository"];
}
}
MQHelper class will take care of reading and writing messages.
using IBM.WMQ;
namespace SampleApplication
{
public class MQHelper
{
MQQueueManager oQueueManager;
MQInfo oMQInfo;
void Main()
{
Console.WriteLine("1.Read Sample Messagen2.Write Sample Message");
var option = Convert.ToInt32(Console.ReadLine());
switch (option)
{
case 1: Connect();
var message = ReadSingleMessage();
Console.WriteLine(message);
break;
case 2: Connect();
message = "";
WriteMessage(message);
break;
default: Console.WriteLine("Invalid Option");
break;
}
Console.ReadLine();
}
private void Connect()
{
try
{
//get connection information
oMQInfo = new MQInfo();
//set the connection properties
MQEnvironment.Hostname = oMQInfo.HostName;
MQEnvironment.Port = Convert.ToInt32(oMQInfo.Port);
MQEnvironment.Channel = oMQInfo.ChannelName;
MQEnvironment.SSLCipherSpec = oMQInfo.SSLCipherSpec;
MQEnvironment.SSLKeyRepository = oMQInfo.SSLKeyRepository;
MQEnvironment.UserId = oMQInfo.UserID;
MQEnvironment.Password = oMQInfo.Password;
MQEnvironment.properties.Add(MQC.TRANSPORT_PROPERTY,
MQC.TRANSPORT_MQSERIES_CLIENT);
oQueueManager = new MQQueueManager(oMQInfo.QueueManagerName);
}
catch (Exception ex)
{
//Log exception
}
}
private string ReadSingleMessage()
{
string sResturnMsg = string.Empty;
try
{
if (oQueueManager != null && oQueueManager.IsConnected)
{
MQQueue oQueue = oQueueManager.AccessQueue(oMQInfo.QueueName,
MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
MQMessage oMessage = new MQMessage();
oMessage.Format = MQC.MQFMT_STRING;
MQGetMessageOptions oGetMessageOptions = new
MQGetMessageOptions();
oQueue.Get(oMessage, oGetMessageOptions);
sResturnMsg = oMessage.ReadString(oMessage.MessageLength);
}
else
{
//Log the exception
sResturnMsg = string.Empty;
}
}
catch (MQException MQexp)
{
//Log the exception
sResturnMsg = string.Empty;
}
catch (Exception exp)
{
//Log the exception
sResturnMsg = string.Empty;
}
return sResturnMsg;
}
private void WriteMessage(string psMessage)
{
try
{
if (oQueueManager != null && oQueueManager.IsConnected)
{
MQQueue oQueue = oQueueManager.AccessQueue(oMQInfo.QueueName,
MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
MQMessage oMessage = new MQMessage();
oMessage.WriteString(psMessage);
oMessage.Format = MQC.MQFMT_STRING;
MQPutMessageOptions oPutMessageOptions = new
MQPutMessageOptions();
oQueue.Put(oMessage, oPutMessageOptions);
}
else
{
//log exception
}
}
catch (MQException MQExp)
{
//log exception
}
catch (Exception ex)
{
//log exception
}
}
}
}
rfhutilc.exe can be used to place or view messages on the MQ remote queue.
You can download the utility from this location-
ftp://ftp.software.ibm.com/software/integration/support/supportpacs/individual
/ih03.zip
Conclusion:
In this article I have explained how we can connect to IBM MQ from C# and read
and write messages. Also I introduced rfhutilc.exe which can be used to place or
view messages on the MQ remote queue.

More Related Content

PDF
발표자료 1인qa로살아남는6가지방법
DOCX
Socjologia rozumiejaca
PDF
Threads 02: Acesso exclusivo e comunicação entre threads
PDF
Threads 10: CompletableFuture
PDF
Curso de Java: Threads
PPT
Unit 2-Design Patterns.ppt
PPT
Struts Ppt 1
PPTX
Sequelize
발표자료 1인qa로살아남는6가지방법
Socjologia rozumiejaca
Threads 02: Acesso exclusivo e comunicação entre threads
Threads 10: CompletableFuture
Curso de Java: Threads
Unit 2-Design Patterns.ppt
Struts Ppt 1
Sequelize

What's hot (20)

PDF
Prod-Like Integration Testing for Distributed Containerized Applications
PPTX
Angular 5 presentation for beginners
PPTX
Introduction to Spring Boot
PPTX
Spring boot
PPTX
Angular Unit Testing
PDF
Angular - Chapter 4 - Data and Event Handling
PDF
cours java complet-2.pdf
PDF
Algoritmos de Agrupamento - Aprendizado não supervisionado
PDF
MVC Architecture
PPTX
Java Unit Testing
PDF
Análise e Modelagem de Software
PDF
POO - 01 - Introdução ao Paradigma Orientado a Objetos
PPTX
Socjologia rozumiejaca
PPTX
Introduction to JUnit
PDF
Padrão Adapter
PDF
ieee 830
PDF
Spring Framework - AOP
PPTX
Angular Unit Testing
PDF
(애자일) 테스트 계획서 샘플
PPTX
Introducing Swagger
Prod-Like Integration Testing for Distributed Containerized Applications
Angular 5 presentation for beginners
Introduction to Spring Boot
Spring boot
Angular Unit Testing
Angular - Chapter 4 - Data and Event Handling
cours java complet-2.pdf
Algoritmos de Agrupamento - Aprendizado não supervisionado
MVC Architecture
Java Unit Testing
Análise e Modelagem de Software
POO - 01 - Introdução ao Paradigma Orientado a Objetos
Socjologia rozumiejaca
Introduction to JUnit
Padrão Adapter
ieee 830
Spring Framework - AOP
Angular Unit Testing
(애자일) 테스트 계획서 샘플
Introducing Swagger
Ad

Viewers also liked (20)

PDF
Bank of America Corporation acquires Merrill Lynch & Co., Inc. Presentation
PPT
2012521131 박소영 io_t시대의ssca
PDF
Hand Key Manual
PDF
Server consolidation with the Dell PowerEdge M620
PDF
XPS™ One™ Sales Aid (2007 2-page flyer)
PDF
I tube tr
PPTX
Workshop 1 - Associazione Italiana di Ingegneria Agraria - Monarca Danilo
PDF
Returns Management: Where are you on the Maturity Curve?
PDF
Industry Perspectives of SDN: Technical Challenges and Business Use Cases
PDF
Sun fire x4140, x4240, x4440 server customer presentation
PPTX
Los Valores
PDF
dell 1996 Annual Report Cover Fiscal 1996 in
PPTX
Dell vs dabur
PPT
Инвестиция в будущее: позвольте Dell представить вам мир ИТ-возможностей
PDF
hp hc notification 2015
DOCX
Praveen birla soft
DOCX
Phat Resume 14Mar2016
DOC
SOP - 2013 Server Build
PDF
Database server comparison: Dell PowerEdge R630 vs. Lenovo ThinkServer RD550
PDF
Exchange server 2010规划与设计
Bank of America Corporation acquires Merrill Lynch & Co., Inc. Presentation
2012521131 박소영 io_t시대의ssca
Hand Key Manual
Server consolidation with the Dell PowerEdge M620
XPS™ One™ Sales Aid (2007 2-page flyer)
I tube tr
Workshop 1 - Associazione Italiana di Ingegneria Agraria - Monarca Danilo
Returns Management: Where are you on the Maturity Curve?
Industry Perspectives of SDN: Technical Challenges and Business Use Cases
Sun fire x4140, x4240, x4440 server customer presentation
Los Valores
dell 1996 Annual Report Cover Fiscal 1996 in
Dell vs dabur
Инвестиция в будущее: позвольте Dell представить вам мир ИТ-возможностей
hp hc notification 2015
Praveen birla soft
Phat Resume 14Mar2016
SOP - 2013 Server Build
Database server comparison: Dell PowerEdge R630 vs. Lenovo ThinkServer RD550
Exchange server 2010规划与设计
Ad

Similar to Ibm mq with c# sending and receiving messages (20)

PPT
IBM Informix dynamic server and websphere MQ integration
PPTX
Building Smart IoT Solutions: Raspberry Pi with Hive MQTT
PPTX
WCF Fundamentals
DOCX
58615764 net-and-j2 ee-web-services
PDF
Jms tutor
PDF
IBM MQ Security Deep Dive
PDF
IBM MQ V8 Security
PPT
MQTC 2016 - IBM MQ Security: Overview & recap
PDF
ESM v5.0 Service Layer Developer's Guide
PDF
ESM v5.0 Service Layer Developer's Guide
PDF
HHM 6887 Managing Your Scalable Applications in an MQ Hybrid Cloud World
PDF
Secure Messages with IBM WebSphere MQ Advanced Message Security
PDF
Infrastructure as Code: Manage your Architecture with Git
PPTX
DevOps, Microservices and Serverless Architecture
PDF
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
PDF
Cohesive Networks Support Docs: VNS3 version 3.5+ API Guide
PPTX
Apache cassandra - future without boundaries (part3)
KEY
Using Apache as an Application Server
PDF
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
PPTX
Cloud Foundry a Developer's Perspective
IBM Informix dynamic server and websphere MQ integration
Building Smart IoT Solutions: Raspberry Pi with Hive MQTT
WCF Fundamentals
58615764 net-and-j2 ee-web-services
Jms tutor
IBM MQ Security Deep Dive
IBM MQ V8 Security
MQTC 2016 - IBM MQ Security: Overview & recap
ESM v5.0 Service Layer Developer's Guide
ESM v5.0 Service Layer Developer's Guide
HHM 6887 Managing Your Scalable Applications in an MQ Hybrid Cloud World
Secure Messages with IBM WebSphere MQ Advanced Message Security
Infrastructure as Code: Manage your Architecture with Git
DevOps, Microservices and Serverless Architecture
PRIVATE CLOUD SERVER IMPLEMENTATIONS FOR DATA STORAGE
Cohesive Networks Support Docs: VNS3 version 3.5+ API Guide
Apache cassandra - future without boundaries (part3)
Using Apache as an Application Server
윈도 닷넷 개발자를 위한 솔루션 클라우드 데브옵스 솔루션
Cloud Foundry a Developer's Perspective

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Approach and Philosophy of On baking technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
cuic standard and advanced reporting.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
KodekX | Application Modernization Development
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Understanding_Digital_Forensics_Presentation.pptx
sap open course for s4hana steps from ECC to s4
20250228 LYD VKU AI Blended-Learning.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Digital-Transformation-Roadmap-for-Companies.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
MIND Revenue Release Quarter 2 2025 Press Release
Approach and Philosophy of On baking technology
Spectral efficient network and resource selection model in 5G networks
Dropbox Q2 2025 Financial Results & Investor Presentation
cuic standard and advanced reporting.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
“AI and Expert System Decision Support & Business Intelligence Systems”
Programs and apps: productivity, graphics, security and other tools
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
KodekX | Application Modernization Development
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Ibm mq with c# sending and receiving messages

  • 1. IBM MQ And C#-Sending And Receiving Messages Introduction: What is IBM MQ? IBM MQ is messaging middleware that simplifies and accelerates the integration of diverse applications and business data across multiple platforms. It uses message queues to facilitate the exchange of information between applications, systems, services and files and simplify the creation and maintenance of business applications. Benefits of IBM MQ  Rapid, seamless connectivity: Offers a single, robust and trusted messaging backbone for dynamic heterogeneous environments.  Secure, reliable message delivery: Preserves message integrity and helps minimize risk of information loss.  Lower cost of ownership: Reduces cost of integration and accelerates time to deployment. Connecting to IBM MQ from C#. Note:This document targets only windows platform. Prerequisites:  We need to install MQ client in order to connect with MQ server. I am using MQv8 Client.  You can download the client software from this link.  If you follow normal installation path it will create folder in this path “C:Program FilesIBMWebSphere MQ”. Note: after installing WMQ client on windows platform, if the folder “SSL” does not get created under {IBM MQ Installation directory}, create “SSL” folder manually.
  • 2.  Also you need to have following connection properties. AMQCLCHL.TAB This is also called Client channel definition table. This binary file contains client connection details and it shall be used to connect to Client. KEY.ARM This is the queue manager certificate and it shall be used by WMQ client while connecting to Server queue manager. Hostname The TCP/IP hostname of the machine on which the WebSphere MQ server resides. Port Number The port to be used. Channel The name of the channel to connect to on the target queue manager. MQ Queue Name  Name of the Queue Queue Manager Name  The name of the queue manager to which to connect. ClientID (UserID) The ID used to identify the WebSphere MQ client Password The password used to verify the identity of the WebSphere MQ Client. Cipher Spec application can establish a connection to a queue manager depends on the CipherSpec specified at the server end of the MQI channel and the CipherSuite specified at the client end. Cipher Suite  The name of the Cipher Suite to be used by SSL.
  • 3. Setting up MQ client To set up MQ client follow the below steps. 1. Copy AMQCLCHL.TAB and Key.arm file to the following path: {Path of IBM MQ Installation directory}/SSL 2. Set the below values as “System Variables” Variable name Value MQCHLLIB {Path of IBM MQ Installation directory}/SSL MQCHLTAB AMQCLCHL.TAB MQSSLKEYR {Path of IBM MQ Installation directory}/SSL 3. Run the command prompt in administrator mode. Create a key database of type CMS using command runmqckm -keydb -create -db "C:Program FilesIBMWebSphere MQSSL key.kdb" - pw password -type cms -expire 365 -stash Here the password is of your choice and please remember this password as this is needed in future. Note: you can find more details about the options in the command in this link- http://www.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.ref.adm.doc/q083860_.htm
  • 4. 4. Add the self signed certificate to key database using the below command. runmqckm -cert -add -db " C:Program FilesIBMWebSphere MQSSLkey.kdb" -pw password -label ibmwebspheremq<userID> -file " C:Program FilesIBMWebSphere MQSSLkey.arm" -format ascii where password is the password you choose in the Step 3 when creating key database of type CMS. In ibmwebspheremq<userID> replace <userID> with client id. this is used as an identifier. Note: Specify the absolute path of the key.arm file.
  • 5. 5. check if the certificate is added successfully using the below command. runmqckm -cert -list -db " C:Program FilesIBMWebSphere MQSSLkey.kdb " -pw password The output of above command must list the certificate ibmwebspheremq<userID> Now as the client is configured Let’s do coding. Note: add reference to the dll amqmdnet.dll. you can find this dll in the MQ installation directory (C:….) In this sample application I am storing all the queue properties in my app.config file. <configuration> <appSettings> <add key="QueueManagerName" value=""/> <add key="QueueName" value=""/> <add key="ChannelName" value=""/> <add key="TransportType" value="TCP"/>
  • 6. <add key="HostName" value=""/> <add key="Port" value=""/> <add key="UserID" value=""/> <add key="Password" value="YourChoice"/> <add key="SSLCipherSpec" value="TLS_RSA_WITH_DES_CBC_SHA"/> <add key="SSLKeyRepository" value="C:Program FilesIBMWebSphere MQsslkey"/> </appSettings> </configuration> And I am using an Info class to fetch these details public class MQInfo { public string QueueManagerName { get; set; } public string QueueName { get; set; } public string ChannelName { get; set; } public string TransportType { get; set; } public string HostName { get; set; } public string Port { get; set; } public string UserID { get; set; } public string Password { get; set; } public string SSLCipherSpec { get; set; } public string SSLKeyRepository { get; set; } public MQInfo() { QueueManagerName = ConfigurationManager.AppSettings["QueueManagerName"]; QueueName = ConfigurationManager.AppSettings["QueueName"]; ChannelName = ConfigurationManager.AppSettings["ChannelName"]; TransportType = ConfigurationManager.AppSettings["TransportType"]; HostName = ConfigurationManager.AppSettings["HostName"]; Port = ConfigurationManager.AppSettings["Port"]; UserID = ConfigurationManager.AppSettings["UserID"]; Password = ConfigurationManager.AppSettings["Password"]; SSLCipherSpec = ConfigurationManager.AppSettings["SSLCipherSpec"]; SSLKeyRepository = ConfigurationManager.AppSettings["SSLKeyRepository"]; } } MQHelper class will take care of reading and writing messages. using IBM.WMQ; namespace SampleApplication {
  • 7. public class MQHelper { MQQueueManager oQueueManager; MQInfo oMQInfo; void Main() { Console.WriteLine("1.Read Sample Messagen2.Write Sample Message"); var option = Convert.ToInt32(Console.ReadLine()); switch (option) { case 1: Connect(); var message = ReadSingleMessage(); Console.WriteLine(message); break; case 2: Connect(); message = ""; WriteMessage(message); break; default: Console.WriteLine("Invalid Option"); break; } Console.ReadLine(); } private void Connect() { try { //get connection information oMQInfo = new MQInfo(); //set the connection properties MQEnvironment.Hostname = oMQInfo.HostName; MQEnvironment.Port = Convert.ToInt32(oMQInfo.Port); MQEnvironment.Channel = oMQInfo.ChannelName; MQEnvironment.SSLCipherSpec = oMQInfo.SSLCipherSpec; MQEnvironment.SSLKeyRepository = oMQInfo.SSLKeyRepository; MQEnvironment.UserId = oMQInfo.UserID; MQEnvironment.Password = oMQInfo.Password; MQEnvironment.properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT); oQueueManager = new MQQueueManager(oMQInfo.QueueManagerName); } catch (Exception ex) { //Log exception }
  • 8. } private string ReadSingleMessage() { string sResturnMsg = string.Empty; try { if (oQueueManager != null && oQueueManager.IsConnected) { MQQueue oQueue = oQueueManager.AccessQueue(oMQInfo.QueueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING); MQMessage oMessage = new MQMessage(); oMessage.Format = MQC.MQFMT_STRING; MQGetMessageOptions oGetMessageOptions = new MQGetMessageOptions(); oQueue.Get(oMessage, oGetMessageOptions); sResturnMsg = oMessage.ReadString(oMessage.MessageLength); } else { //Log the exception sResturnMsg = string.Empty; } } catch (MQException MQexp) { //Log the exception sResturnMsg = string.Empty; } catch (Exception exp) { //Log the exception sResturnMsg = string.Empty; } return sResturnMsg; } private void WriteMessage(string psMessage) { try { if (oQueueManager != null && oQueueManager.IsConnected) { MQQueue oQueue = oQueueManager.AccessQueue(oMQInfo.QueueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING); MQMessage oMessage = new MQMessage(); oMessage.WriteString(psMessage); oMessage.Format = MQC.MQFMT_STRING; MQPutMessageOptions oPutMessageOptions = new MQPutMessageOptions(); oQueue.Put(oMessage, oPutMessageOptions);
  • 9. } else { //log exception } } catch (MQException MQExp) { //log exception } catch (Exception ex) { //log exception } } } }
  • 10. rfhutilc.exe can be used to place or view messages on the MQ remote queue. You can download the utility from this location- ftp://ftp.software.ibm.com/software/integration/support/supportpacs/individual /ih03.zip Conclusion: In this article I have explained how we can connect to IBM MQ from C# and read and write messages. Also I introduced rfhutilc.exe which can be used to place or view messages on the MQ remote queue.