Following this post: Get Active QM Instance from Multi Instance Queue Manager and connect
I have created a connection
XMSFactoryFactory factory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
IConnectionFactory connectionProperties = factory.CreateConnectionFactory();
connectionProperties.SetIntProperty(XMSC.WMQ_CLIENT_RECONNECT_OPTIONS, XMSC.WMQ_CLIENT_RECONNECT_Q_MGR);
connectionProperties.SetStringProperty(XMSC.WMQ_CONNECTION_NAME_LIST, String.Format("{0}({1}),{2}({3})", element.Host1, element.Port1, element.Host2, element.Port2));
connectionProperties.SetIntProperty(XMSC.WMQ_CLIENT_RECONNECT_TIMEOUT, XMSC.WMQ_CLIENT_RECONNECT_TIMEOUT_DEFAULT);
connectionProperties.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, element.QueueManager);
connectionProperties.SetStringProperty(XMSC.WMQ_CHANNEL, element.Channel);
connectionProperties.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
connectionProperties.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1);
connectionProperties.SetBooleanProperty(XMSC.WMQ_USE_CONNECTION_POOLING, true);
then followed by
try
{
using (IConnection connection = _connectionProperties.CreateConnection())
{
connection.Start();
using (ISession session = connection.CreateSession(true, AcknowledgeMode.AutoAcknowledge))
{
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
using (IDestination responseQueue = session.CreateQueue(replyToRequestQueue ? _requestQueueName : _responseQueueName))
{
using (IMessageProducer producer = session.CreateProducer(responseQueue))
{
IMessage response = session.CreateTextMessage(message);
if (!string.IsNullOrEmpty(correlationId))
{
response.JMSCorrelationID = correlationId;
}
producer.Send(response);
}
}
scope.Complete();
}
}
}
}
catch (XMSException xmse)
{
if (xmse.LinkedException != null)
{
Trace.TraceError(string.Format(MQTraceMessageFormat,
DateTime.Now,
TraceMessageType.Error,
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.IsThreadPoolThread ? "Threadpool " + Name : Thread.CurrentThread.Name,
null, null,
"XMSException.LinkedException on (SendTextMessage) sending message to " + this +
" / xmse.LinkedException.Message : " + xmse.LinkedException.Message +
" / xmse.Message : " + xmse.Message +
" / xmse.LinkedException.StackTrace: " + xmse.LinkedException.StackTrace,
" / xmse.StackTrace: " + xmse.StackTrace,
null));
}
else
{
Trace.TraceError(string.Format(MQTraceMessageFormat,
DateTime.Now,
TraceMessageType.Error,
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.IsThreadPoolThread ? "Threadpool " + Name : Thread.CurrentThread.Name,
null, null,
"XMSException on (SendTextMessage) sending message to " + this +
" / xmse.Message : " + xmse.Message +
" / xmse.StackTrace: " + xmse.StackTrace,
null));
}
}
catch (MQException mqex)
{
Trace.TraceError(string.Format(MQTraceMessageFormat,
DateTime.Now,
TraceMessageType.Error,
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.IsThreadPoolThread ? "Threadpool " + Name : Thread.CurrentThread.Name,
null, null,
"MQException cc on (SendTextMessage) sending message to " + this +
" Exception: " + mqex.Message +
" CompletionCode: " + mqex.CompletionCode +
" ReasonCode: " + mqex.ReasonCode +
" Stack Trace: " + mqex.StackTrace,
null));
}
catch (IOException ioex)
{
Trace.TraceError(string.Format(MQTraceMessageFormat,
DateTime.Now,
TraceMessageType.Error,
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.IsThreadPoolThread ? "Threadpool " + Name : Thread.CurrentThread.Name,
null, null,
"IOException ioex on (SendTextMessage) sending message to " + this +
" Exception: " + ioex.Message +
" Stack Trace: " + ioex.StackTrace,
null));
}
catch (Exception ex)
{
Trace.TraceError(string.Format(MQTraceMessageFormat,
DateTime.Now,
TraceMessageType.Error,
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.IsThreadPoolThread ? "Threadpool " + Name : Thread.CurrentThread.Name,
null, null,
"Exception ex on (SendTextMessage) sending message to " + this +
" Exception: " + ex.Message +
" Stack Trace: " + ex.StackTrace,
null));
}
}
to send message, however it threw exception at the last line producer.Send(response):
renamed.exe Error: 0 : |8/15/2017 10:17:49 AM|Error|25|Threadpool XYZ|||XMSException.LinkedException on (SendTextMessage) sending message to Queue handler ABC:(In ABC.XYZ.REQUEST / Out XYZ.ABC.RESPONSE) / xmse.LinkedException.Message : 2012 / xmse.Message : Failed to send a message to destination XYZ.ABC.RESPONSE.
XMS attempted to perform an MQPUT or MQPUT1; however WebSphere MQ reported an error.
Use the linked exception to determine the cause of this error. / xmse.LinkedException.StackTrace: | / xmse.StackTrace: at IBM.XMS.Client.WMQ.ProducerShadow.CheckNmqiCallSuccess(String messageid, WmqDestination destination, String probeid, Int32 cc, Int32 rc)
at IBM.XMS.Client.WMQ.SpiIdentifiedProducerShadow.SendInternal(MQMessageDescriptor md, Byte[] buffers, Int32 msgLength)
at IBM.XMS.Client.WMQ.ProducerShadow.Send(WmqDestination destAtSendCall, WmqMessage message)
at IBM.XMS.Client.WMQ.WmqMessageProducer.Send(ProviderDestination destAtSendCall, ProviderMessage message)
at IBM.XMS.Client.Impl.XmsMessageProducerImpl.SendMessage(IMessage message, XmsDestinationImpl dest)
at IBM.XMS.Client.Impl.XmsMessageProducerImpl.Send_(Boolean inIdentifiedContext, XmsDestinationImpl dest, IMessage message, DeliveryMode deliveryMode, Int32 priority, Int64 timeToLive, Boolean explicitDlvModePriorityAndTimeToLive)
at IBM.XMS.Client.Impl.XmsMessageProducerImpl.Send(IMessage message)
at DVS.Services.Common.MQHandler.QueueHandler.SendTextMessage(String message, String correlationId, Boolean replyToRequestQueue)
From the trace I can see the producer has my two active/standby host in the connection name list, but also "localhost" as host_name and 1414 as port, is that why I cannot connect to it?
producer: XMSC_WMQ_BROKER_PUBQ_QMGR :
XMSC_CONNECTION_TYPE_NAME : IBM.XMS.Client.WMQ
XMSC_DISABLE_MSG_ID : False
XMSC_WMQ_RESOLVED_QUEUE_MANAGER_ID : QM1_2017-08-02_15.25.10
XMSC_WMQ_CLEANUP_INTERVAL : 3600000
XMSC_WMQ_BROKER_PUBQ : SYSTEM.BROKER.DEFAULT.STREAM
XMSC_WMQ_BROKER_SUBQ : SYSTEM.JMS.ND.SUBSCRIBER.QUEUE
XMSC_WMQ_PUB_ACK_INTERVAL : 25
targetClient : 0
XMSC_WMQ_CLEANUP_LEVEL : 1
XMSC_WMQ_MESSAGE_RETENTION : 1
XMSC_WMQ_PORT : 1414
XMSC_WMQ_PROVIDER_VERSION : 7
CCSID : 1208
deliveryMode : 2
XMSC_ADMIN_OBJECT_TYPE : 20
brokerVersion : 0
XMSC_WMQ_USE_CONNECTION_POOLING : True
XMSC_WMQ_TEMP_Q_PREFIX :
XMSC_ACKNOWLEDGE_MODE : 4
XMSC_WMQ_BROKER_CONTROLQ : SYSTEM.BROKER.CONTROL.QUEUE
failIfQuiesce : 1
XMSC_WMQ_MESSAGE_SELECTION : 0
XMSC_ASYNC_EXCEPTIONS : -1
timeToLive : 0
XMSC_WMQ_CONNECTION_MODE : 1
XMSC_WMQ_RESOLVED_QUEUE_MANAGER : QM1
XMSC_WMQ_CONNECTION_NAME_LIST : host1(11111),host2(11111)
XMSC_WMQ_QMGR_CCSID : 819
XMSC_WMQ_SHARE_CONV_ALLOWED : 1
XMSC_WMQ_CLIENT_RECONNECT_TIMEOUT : 1800
XMSC_WMQ_MAP_NAME_STYLE : True
XMSC_PASSWORD : ********
priority : 4
XMSC_WMQ_LOCAL_ADDRESS :
XMSC_WMQ_MAX_BUFFER_SIZE : 1000
XMSC_WMQ_CONNECT_OPTIONS : 0
XMSC_DISABLE_MSG_TS : False
XMSC_WMQ_BROKER_QMGR :
XMSC_WMQ_CLIENT_RECONNECT_OPTIONS : 16777216
version : 7
XMSC_WMQ_CONNECTION_TAG : System.Byte[]
encoding : 546
XMSC_WMQ_POLLING_INTERVAL : 5000
XMSC_WMQ_RESCAN_INTERVAL : 5000
XMSC_WMQ_TEMPORARY_MODEL : SYSTEM.DEFAULT.MODEL.QUEUE
XMSC_WMQ_CHANNEL : MY.SVC.SVRCONN.P
XMSC_CONNECTION_TYPE : 1
XMSC_WMQ_SYNCPOINT_ALL_GETS : False
XMSC_WMQ_HOST_NAME : localhost
XMSC_WMQ_QUEUE_MANAGER : QM1
wildcardFormat : 0
XMSC_WMQ_BROKER_DUR_SUBQ : SYSTEM.JMS.D.SUBSCRIBER.QUEUE
XMSC_TRANSACTED : True
XMSC_WMQ_MSG_BATCH_SIZE : 10