SlideShare a Scribd company logo
6
Most read
7
Most read
8
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

What's hot (20)

PDF
Angular and The Case for RxJS
Sandi Barr
 
PDF
Angular Observables & RxJS Introduction
Rahat Khanna a.k.a mAppMechanic
 
PPTX
OAuth2 + API Security
Amila Paranawithana
 
PPTX
OpenID Connect: An Overview
Pat Patterson
 
PDF
DataPower API Gateway Performance Benchmarks
IBM DataPower Gateway
 
PDF
OAuth2 and Spring Security
Orest Ivasiv
 
PPTX
Gateway/APIC security
Shiu-Fun Poon
 
PPTX
REST API Design & Development
Ashok Pundit
 
PPTX
Webauthn Authentication
Okta-Inc
 
PPTX
B4USolution_API-Testing
b4usolution .
 
PDF
OAuth & OpenID Connect Deep Dive
Nordic APIs
 
PDF
OpenID for Verifiable Credentials
Torsten Lodderstedt
 
PDF
Postman
Igor Shubovych
 
PDF
Token, token... From SAML to OIDC
Shiu-Fun Poon
 
PPTX
An Introduction to OAuth2
Aaron Parecki
 
PDF
Automate REST API Testing
TechWell
 
ODP
Introduction to Swagger
Knoldus Inc.
 
PPTX
Api Testing
Vishwanath KC
 
PDF
Introduction to Self Sovereign Identity
Heather Vescent
 
PPTX
OpenID for Verifiable Credentials
Torsten Lodderstedt
 
Angular and The Case for RxJS
Sandi Barr
 
Angular Observables & RxJS Introduction
Rahat Khanna a.k.a mAppMechanic
 
OAuth2 + API Security
Amila Paranawithana
 
OpenID Connect: An Overview
Pat Patterson
 
DataPower API Gateway Performance Benchmarks
IBM DataPower Gateway
 
OAuth2 and Spring Security
Orest Ivasiv
 
Gateway/APIC security
Shiu-Fun Poon
 
REST API Design & Development
Ashok Pundit
 
Webauthn Authentication
Okta-Inc
 
B4USolution_API-Testing
b4usolution .
 
OAuth & OpenID Connect Deep Dive
Nordic APIs
 
OpenID for Verifiable Credentials
Torsten Lodderstedt
 
Token, token... From SAML to OIDC
Shiu-Fun Poon
 
An Introduction to OAuth2
Aaron Parecki
 
Automate REST API Testing
TechWell
 
Introduction to Swagger
Knoldus Inc.
 
Api Testing
Vishwanath KC
 
Introduction to Self Sovereign Identity
Heather Vescent
 
OpenID for Verifiable Credentials
Torsten Lodderstedt
 

Viewers also liked (20)

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

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

PPT
IBM WebSphere MQ Introduction
ejlp12
 
PPTX
CTU 2017 I173 - how to transform your messaging environment to a secure messa...
Robert Parker
 
PPTX
IBM Web Shpere MQ ppt
Parth Shah
 
DOC
WebSphere MQ Admin Classroom Training
Srihitha Technologies
 
PDF
Amqtac05
Burhan786
 
PDF
IBM MQ Basics
subbareddyalamur
 
PDF
Websphere MQ admin guide
Ram Babu
 
PDF
IBM What's New in MQ V8
IBM Systems UKI
 
PDF
Mq ssl channels_on_windows
karthickmsit
 
PDF
IBM MQ Channel Authentication
IBM Systems UKI
 
PDF
WebSphere MQ tutorial
Joseph's WebSphere Library
 
PDF
An Introduction to the Message Queuing Technology & IBM WebSphere MQ
Ravi Yogesh
 
PDF
IBM MQ Security Deep Dive
IBM Systems UKI
 
DOC
WMQ 7.5 Admin Course content
Ram Babu
 
PDF
Simplifying IBM MQ Security in your MQ estate
Robert Parker
 
PDF
IBM MQ Appliance - Administration simplified
Anthony Beardsmore
 
PDF
IBM MQ V8 Security: Latest Features Deep-Dive
Morag Hughson
 
PPTX
IBM MQ Advanced - IBM InterConnect 2016
Leif Davidsen
 
PDF
IBM MQ V8 Security
Morag Hughson
 
PDF
Websphere MQ (MQSeries) fundamentals
Biju Nair
 
IBM WebSphere MQ Introduction
ejlp12
 
CTU 2017 I173 - how to transform your messaging environment to a secure messa...
Robert Parker
 
IBM Web Shpere MQ ppt
Parth Shah
 
WebSphere MQ Admin Classroom Training
Srihitha Technologies
 
Amqtac05
Burhan786
 
IBM MQ Basics
subbareddyalamur
 
Websphere MQ admin guide
Ram Babu
 
IBM What's New in MQ V8
IBM Systems UKI
 
Mq ssl channels_on_windows
karthickmsit
 
IBM MQ Channel Authentication
IBM Systems UKI
 
WebSphere MQ tutorial
Joseph's WebSphere Library
 
An Introduction to the Message Queuing Technology & IBM WebSphere MQ
Ravi Yogesh
 
IBM MQ Security Deep Dive
IBM Systems UKI
 
WMQ 7.5 Admin Course content
Ram Babu
 
Simplifying IBM MQ Security in your MQ estate
Robert Parker
 
IBM MQ Appliance - Administration simplified
Anthony Beardsmore
 
IBM MQ V8 Security: Latest Features Deep-Dive
Morag Hughson
 
IBM MQ Advanced - IBM InterConnect 2016
Leif Davidsen
 
IBM MQ V8 Security
Morag Hughson
 
Websphere MQ (MQSeries) fundamentals
Biju Nair
 
Ad

Recently uploaded (20)

PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
July Patch Tuesday
Ivanti
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
July Patch Tuesday
Ivanti
 

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.