I am new to IBM Websphere MQ.
In our projet, I have implemented code to read messages from IBM MQ.
I have installed IBM WebSphere client and I am using references of IBM.XMS and IBM.XMS.Client.WMQ to create the connection and read the message from the queue.
XMSFactoryFactory xff = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
IConnectionFactory cf = xff.CreateConnectionFactory();
I have set the necessary properties like HostName, Channel, Port, QueueManager.
I have created the MessageListener:
MessageListener messageListener = new MessageListener(Method to process the message);
I have assigned listener to consumer:
consumer.MessageListener = messageListener;
I am able to connect to queue manager, read the message and display that message in WPF window.
Now for above code I have to write the UnitTest.
As per my knowledge, in unittest we won't be creating connection and reading from queue so how can I mock above code so that I can pass dummy message and check that.
The XMS API you are calling will actually communicate with a queue manager. So without a queue manager the API's will fail and so will the unit test.
Related
how to detect if the message broker configuration is valid or if the connection to the message broker is lost using Mass Transit to RabbitMQ? When publishing messages when RabbitMQ is present does not seems to complain if there is no broker connection right away and seems to recover when the RabbitMQ server comes up. Is there a way to listen in on the connection events and warn if the configuration is not valid?
If you use .NET Core and configure MassTransit as per the docs, you can resolve the instance of IBusHealth and use it in your service.
The AddMassTransit method registers the default instance, which you can ask for the bus health status at any time. That's the method code:
public HealthResult CheckHealth()
{
var endpointHealthResult = _endpointHealth.CheckHealth();
var data = new Dictionary<string, object> {["Endpoints"] = endpointHealthResult.Data};
return _healthy && endpointHealthResult.Status == BusHealthStatus.Healthy
? HealthResult.Healthy("Ready", data)
: HealthResult.Unhealthy($"Not ready: {_failureMessage}", data: data);
}
As you can see, if you call busHealth.CheckHealth() it will return either Healthy or Unhealthy and in the latter case would also give you the list of failing endpoints.
Since BusHealth only monitors the bus itself and all its receive endpoints, you might not get notified when your service failed to publish messages.
You can use the diagnostics listener or create your own publish or send observer, which is called before and after publish/send and on any failure.
I'm developing a new service based on our infrastructure that uses IBMMQ 8.0 (I've to admit that I'm not a guru of IBMMQ and I've used it as a simple integration without diving in it's implementation).
I'm trying right now to use It with amqpnetlite (in order to use it with .NET Core).
Till now here's my snippet
Address address = new Address("amqp://10.112.62.102:1414");
Connection connection = new Connection(address);
Session session = new Session(connection);
Message message = new Message("Hello AMQP!");
var sender = new SenderLink(session, "AONMQCOL1", "MQ_TEST");
sender.Send(message);
Console.WriteLine("Sent Hello AMQP!");
I got an exception AmqpException: The transport 'TcpTransport' is closed. when performing the Send. On the connection object I've got IsClosed = false so I think the connection is open.
Just as confirmation, what should I put as "address" and "name" on the SenderLink's constructor?
Thanks
What is the exact version of MQ Server you are running? i.e. issue the dspmqver command.
You need to be at Command Level 801 which was added in Fixack 2 of IBM MQ v8. i.e. IBM MQ v8.0.0.2. See here for more details.
Did you start the AMQP service and then start the channel?
i.e. runmqsc commands:
START SERVICE(SYSTEM.AMQP.SERVICE)
START CHANNEL(SYSTEM.DEF.AMQP)
Finally, are you connecting to the correct port #? The default port # is 5672.
I am trying to connect to MQ using XMS .Net. The MQ is currently setup on the server and using IBM.WMQ I am able to connect to it. Now I want to explore the IBM XMS as it supports API so in future we can try connecting to MQ from .net full-framework or .net core clients.
Spent 2 days over the web but not able to find a full sample where this is implemented. I also don't want to install the MQ client on my local machine. Is there a way to do this? Are there any good articles available for the same?
Following link provides an overview of XMS.NET
http://www-01.ibm.com/support/docview.wss?uid=swg27024064
IBM MQ Redistributable package can be used to develop MQ .NET applications without installing the Client.You will have to use MQ v9.0.5 or above to use XMS.NET client.You can download the latest redistributable package from the following link
9.1.0 IBM MQ C and .NET redistributable client for Windows x64
If you have MQ client install then there are samples located at "MQ_INSTALL_PATH\Tools\dotnet\samples\cs\xms\simple\wmq" and following link provides a brief description about the samples
https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.xms.doc/xms_csamp.html
Following is the code sample to get a message asynchronously using Message listeners.
/// <summary>
/// Setup connection to MQ queue manager using XMS .NET
/// </summary>
private void ibmmqSetupConnection()
{
XMSFactoryFactory factoryFactory;
IConnectionFactory cf;
IDestination destination;
IMessageConsumer consumerAsync;
MessageListener messageListener;
// Get an instance of factory.
factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
// Create WMQ Connection Factory.
cf = factoryFactory.CreateConnectionFactory();
// Set the properties
cf.SetStringProperty(XMSC.WMQ_HOST_NAME, "host.ibm.com");
cf.SetIntProperty(XMSC.WMQ_PORT, 1414);
cf.SetStringProperty(XMSC.WMQ_CHANNEL, "QM.SVRCONN");
cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "QM1");
cf.SetStringProperty(XMSC.USERID, "myuserid");
cf.SetStringProperty(XMSC.PASSWORD, "passw0rd");
// Create connection.
connectionWMQ = cf.CreateConnection();
// Create session with client acknowledge so that we can acknowledge
// only if message is sent to Azure Service Bus queue
sessionWMQ = connectionWMQ.CreateSession(false, AcknowledgeMode.ClientAcknowledge);
// Create destination
destination = sessionWMQ.CreateQueue("INPUTQ");
// Create consumer
consumerAsync = sessionWMQ.CreateConsumer(destination);
// Setup a message listener and assign it to consumer
messageListener = new MessageListener(OnMessageCallback);
consumerAsync.MessageListener = messageListener;
// Start the connection to receive messages.
connectionWMQ.Start();
// Wait for messages till a key is pressed by user
Console.ReadKey();
// Cleanup
consumerAsync.Close();
destination.Dispose();
sessionWMQ.Dispose();
connectionWMQ.Close();
}
I'm trying to connect to an IBM WebSphere MQ 8.x, but what should be simple as it's with RabbitMQ seems so difficult on IBM world.
I've created a Console Application (.NET Framework), referenced the amqmdnet.dll 8.0.0.10)
and here's my snippet
var connectionName = "X.X.X.X(4418)";
Hashtable properties = new Hashtable();
properties.Add(MQC.CONNECTION_NAME_PROPERTY, connectionName);
properties.Add(MQC.CHANNEL_PROPERTY,"TEST_XXX_RECEIVER");
var mqQMgr = new MQQueueManager("DEFAULT.XXXMQCOL1",properties );
mqQMgr.Connect();
What I got when trying to connect is IBM.WMQ.MQException: 'MQRC_Q_MGR_NAME_ERROR'
For that concern the Queue name I've put the name I found on the node
The Channel property is a channel I've defined in the queue node of websphere
I've tried to telnet on ip:port and it connects
Any suggestion?
UPDATE #1
Even if I do "Start" from context menu, it remains inactive, can this lead to the constructor's hang?
UPDATE #2
I've managed it. I was going wrong on two steps
I have the LISTENER.TCP stopped under the listeners
I was pointing at 4418 which is the Queue Manager port and I had to point at 1414 (Listener.TCP port)
Now I'm able to connect, admin you can close it
You appear to be using sender and/or receiver channels. Use SVRCONN for clients
I'm currently using .Net 4.5 websocket package to support websocket service on windows 2012 server.
Using WebSocketCollection object I'm succesfully able to broadcast message to all the clients.
private static WebSocketCollection m_clients = new WebSocketCollection ();
m_clients.Broadcast(“Hello all”));
Here how to be sure all clients have received broadcasted messages? If some clients couldn't able to receive message how can I track those error messages? What king of error handling mechanism shall I need to use?
There is a onError virtual function. But I'm not sure how it will work during failure case of broadcasted message.
public virtual void OnError();
Could you not get the clients to "Acknowledge" the receipt of a packet, if a client does not Acknowledge the packet then chances are it wasn't received correctly.
If you are just wanting to keep the connection alive send a "Ping" message to the client before timeout. Likewise you could code the client to Ping the server at a scheduled time, if no Ping received then that could indicate that there is a problem?