What is MQ Series?
System for sending messages between multiple platforms, It supports multiple platforms, protocol. This help us to transfer data from one system to another.
Installation of MQ Series.
The MQ Series consists of server and client, I downloaded the trial version of same from IBM site. You need to install the server & client on different machine, I tried to install on same but it did not work for me.Server:
WS_MQ_V7.1.0.3_TRIAL_FOR_WINDOWS_ML
Client:
mqc7_7.0.1.6_winInstall the server, For below provide domain username. Also "IBM Websphere MQ" will run using this username.
Tick the checkbox "Continue with this user account".
Once installed and before configuring "IBM Websphere MQ Explorer." just make sure service "IBM Websphere MQ" is running.
Creating Queue Manager:
In the explorer, create an new Queue manager, call this QUEUE_MANAGER.
Creating Queue:
Click New->Local Queue, name it QUEUE_LOCAL
Creating Channel:
Select Channels--> New "Server-Connection Channel"
Name the channel as SVR_RCV_CHANNEL
Once your server is ready, Install client in local machine.
Next is to code the connection with MQ Series.
Create a New Windows Form Application.
Add new class to it as "MQClass".
Following parameters are required to initiate connection to the MQ Series:
1) Host Name: Machine name where server is installed.
2) Channel Name: Channel through which you are planning to connect to the server.
3) Port on which the Server is listening, Default port is 1414.
AddReference: amqmdnet.dll which is located in your bin folder
Include namespace: IBM.WMQ;
Connecting to the MQ Series server
public string ConnectMQ()
{
String strReturn = "";
try
{
//MQEnvironment.Port = 1414;
//MQEnvironment.Channel = channelName;
//MQEnvironment.Hostname = "localhost";
Hashtable properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
properties.Add(MQC.HOST_NAME_PROPERTY, "hostmachinename");
properties.Add(MQC.PORT_PROPERTY, 1414);
properties.Add(MQC.CHANNEL_PROPERTY, "SVR_RCV_CHANNEL");
// properties.Add(MQC.USER_ID_PROPERTY, "UserName");
// properties.Add(MQC.PASSWORD_PROPERTY, "hhh");
queueManager = new MQQueueManager("QUEUE_MANAGER ", properties);
strReturn = "Connected Successfully";
}
catch (MQException exp)
{
strReturn = "Exception: " + exp.Message;
}
return strReturn;
}
User the same user through which you are running the MQ Series service.
If you get the Error "mqrc_not_authorized" then make sure the Admin user is not blocked, which is by default blocked.
Go to Channels--> ChannelAuthrizationRecords and remove the blocked user.
Delete the channel authorization record if any.
Once you have connected to Queue manager using channel, Now it's time to pass some message and read the message.
Let's see how to pass the message to the queue,
public string WriteMsg(string strInputMsg)
{
string strReturn = "";
try
{
//first get the queue object, by connecting to queue created
mqQueue = queueManager.AccessQueue(QueueName,
MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
message = strInputMsg;
1
//create the message which has to be passed to queue.
mqMessage = new MQMessage();
//add some content to the message
mqMessage.WriteString(message);
mqMessage.Format = MQC.MQFMT_STRING;
queuePutMessageOptions = new MQPutMessageOptions();
//go with the default message options
mqQueue.Put(mqMessage, queuePutMessageOptions);
//return success message
strReturn = "Message sent to the queue successfully";
}
catch (MQException MQexp)
{
strReturn = "Exception: " + MQexp.Message;
}
catch (Exception exp)
{
strReturn = "Exception: " + exp.Message;
}
finally
{
if (mqQueue.OpenStatus)
mqQueue.Close();
}
return strReturn;
}
No comments:
Post a Comment