0

I'm using the IBM websphere XMS API to connect and send messages to the mainframe. However, every message sent is sent through a new local port. Is there a way to set this to a fixed port?

A new port is created locally when the following line is hit:

var connContext = new XMSConnectionContext(connFactory.CreateConnection(), sendQ, replyQ, mqProfile, DateTime.Now.AddSeconds(qm.MqConfiguration.ConnectionPoolExpiryTime));

The code I'm using is

    public IMQMessage Message { get; set; }

    public void Initialise(IMQMessage message, QueueSet queueSet, QueueManager queueManager)
    {
        Message = message;
        if (_connContext.ContainsKey(message.MessageId)) return;
        _connContext.TryAdd(message.MessageId, ConnectQueueSet(queueSet, queueManager));
        _connContext[message.MessageId].Connection.Start();
    }

    private XMSConnectionContext ConnectQueueSet(MQQueueSet queueSet, QueueManager qm)
    {
        var mqProfile = GetProfile(queueSet);

        var xmsFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
        var connFactory = xmsFactory.CreateConnectionFactory();

        connFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, mqProfile.ServerName);
        connFactory.SetIntProperty(XMSC.WMQ_PORT, mqProfile.Port);
        connFactory.SetStringProperty(XMSC.WMQ_CHANNEL, mqProfile.ChannelName);
        connFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, mqProfile.QueueManagerName);
        connFactory.SetIntProperty(XMSC.WMQ_FAIL_IF_QUIESCE, 1);
        connFactory.SetIntProperty(XMSC.WMQ_SHARE_CONV_ALLOWED, XMSC.WMQ_SHARE_CONV_ALLOWED_YES);
        connFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);

We've tried

        connFactory.SetStringProperty(XMSC.XMSC_WMQ_LOCAL_ADDRESS,"(45000,45010)");

We've also tried

        connFactory.SetStringProperty(XMSC.XMSC_WMQ_LOCAL_ADDRESS,"localhost(45000,45010)");

We've also tried

        connFactory.SetStringProperty(XMSC.XMSC_WMQ_LOCAL_ADDRESS,"192.168.12.156(45000,45010)");

End of tests and the rest below is as it was.

        IDestination sendQ = xmsFactory.CreateQueue(string.Format("queue://{0}/{1}?targetClient=1", mqProfile.QueueManagerName, mqProfile.RequestQueue));
        IDestination replyQ = xmsFactory.CreateQueue(string.Format("queue://{0}/{1}?targetClient=1", mqProfile.QueueManagerName, mqProfile.ReplyQueue));

        var connContext = new XMSConnectionContext(connFactory.CreateConnection(), sendQ, replyQ, mqProfile, DateTime.Now.AddSeconds(qm.MqConfiguration.ConnectionPoolExpiryTime));

        QueueManager.Log.DebugFormat("XMSConnectionContext-Instantiated: ProfileName={0} SendQ={1}, ReplyQ={2}, ConnectionMetaData={3}", connContext.ProfileName, connContext.SendQ, connContext.ReplyQ, connContext.Connection);

        return connContext;
    }

    public void Close()
    {
        if (_connContext != null)
        {
            _connContext[Message.MessageId].Connection.Stop();
        }

    }

Any help would be appreciated. Thanks.

Silent Fart
  • 111
  • 2
  • 13

1 Answers1

0

XMS .NET has a connection factory property, XMSC_WMQ_LOCAL_ADDRESS that lets you specify a local port to be used while connecting to a queue manager. More details here

Shashi
  • 14,980
  • 2
  • 33
  • 52
  • I'll give this a try when I'm back in on Monday. Thank you. – Silent Fart May 07 '16 at 10:58
  • Thank you for that but unfortunately that affects the mainframe settings and not the windows one. – Silent Fart May 25 '16 at 17:33
  • I am surprised. Could you please post the code where you are setting the property? – Shashi May 25 '16 at 23:32
  • I've updated the code with the 3 approaches we tried. Thanks. – Silent Fart Jun 02 '16 at 20:43
  • I have been checking around. Will come back with some update soon. – Shashi Jun 06 '16 at 14:06
  • You mentioned "but unfortunately that affects the mainframe settings and not the windows one.". Can you update your question on what you mean by this?. The local address applies to the machine where XMS application is running. Application would use any of the TCP port from specified range. – Shashi Jun 07 '16 at 05:11
  • Hi. Thanks for looking around. By that I meant that it affects the actual mainframe connection. So I have a config file that has IP, port, queues, channel, etc.. to communicate with the mainframe. If I set the XMSC_WMQ_LOCAL_ADDRESS as stated in the question, it tries to send/receive all the messages to what I've set for XMSC_WMQ_LOCAL_ADDRESS instead of using the config file even though I've not made any further code changes besides what I have in the question. From what I saw it assumes that the mainframe is on that connection. – Silent Fart Jun 09 '16 at 20:00