When creating durable subscriber by using of Ibm.Xms, you may get following exception:
"ClientId on the connection has not been set. Please set the Client ID on the Connection object or using the ConnectionFactory in order to use this functionality."
or this one:
CWSMQ0115E: Use of an un-initialised ClientId is not permitted. The ClientId on the connection has not been set. Please set the Client ID on the Connection object or using the ConnectionFactory in order to use this functionality.
In general this platform allows you to create two kinds of consumers: Durable and none durable one. According to IBM notation, the first one is known as Consumer and second one as Durable Subscriber.
To create the none durable consumer use following code:
IDestination destination = ...
session.CreateConsumer(destination);
Similar, durable subscriber can be created with following code:
IDestination destination = ...
connection.ClientID = "SomeUniqueText";
session.CreateConsumer(destination);
Here is the full code. If the red-marked line is missing, the exception above will be thrown:
Unformatted code below:
using System; using System.Collections.Generic; using System.Text; using IBM.XMS;
namespace Ibm.XmlConsumer { class Program { static void Main(string[] args) { XMSFactoryFactory factory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
IConnectionFactory cf = factory.CreateConnectionFactory();
cf.SetStringProperty(XMSC.WMQ_HOST_NAME, "192.168.0.131"); cf.SetIntProperty(XMSC.WMQ_PORT, 1414); cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, 1); // Means client cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "QM1"); cf.SetIntProperty(XMSC.WMQ_BROKER_VERSION, 0); // Means brocker cf.SetStringProperty(XMSC.JMS_IBM_MSGTYPE, "bytes"); // Binary message
//using (IConnectionFactory connectionFactory = cf.CreateConnection("UserId", "Password")) using (IConnection connection = cf.CreateConnection(null, null)) { connection.ClientID = "SomeUniqueText"; using (ISession session = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge)) { using (IDestination destination = session.CreateTopic("topic://daenet.eu/servicebus")) { destination.SetIntProperty(XMSC.DELIVERY_MODE, 1); //"non-persistent" //using (IMessageConsumer consumer = session.CreateConsumer(destination)) using (IMessageConsumer consumer = session.CreateDurableSubscriber(destination, "hello durable world")) { connection.Start();
int cnt = 3;
IMessage recvMsg = null; while (--cnt > 0) { // Receive the message recvMsg = consumer.Receive(30000); } } } } } } } }
|
Posted
Sep 12 2008, 11:36 PM
by
Damir Dobric