简体   繁体   中英

Connecting to Websphere MQ queue manager works in application A but not in application B

I have two console applications, A and B . The application A was created for test purposes and works as expected. The application B does not work although it is basically a copy-paste of A 's code:

System.Console.Write("User Name: ");
string username = System.Console.ReadLine();
System.Console.Write("Password: ");
string password = ConsoleReadPassword();
System.Console.WriteLine();

//user and password required because I am also a privileged user 
//(member of mqm group)
MQEnvironment.UserId = username;
MQEnvironment.Password = password;

//for application B this line throws exception with code 2538
var queueManager = new MQQueueManager("TEST.QUEUE.MANAGER", "CLIENT.CONN.CHANNEL", "localhost(1414)");

Error code 2538 means "Host not available" which is weird because application A has no problems connecting to the same host.

This is how the MQ Server looks in MQ Explorer:

Queue managers: 队列管理器

Queues: s列

Listeners: 听众

Channels: 频道 Two server channels

Channel auth records: 频道认证记录 Default channel authentication record which prevents MQ admins from connecting to queue managers. It was slightly modified (added ~ prefix) so now it does not block anyone.

The MQ Server and applications are running on the same machine so imho network problems are excluded.

The queue manager error log does not report any errors but the general error log looks like this:

08/02/2016 15:15:23 - Process(13720.10) User([username]) Program(B.EXE) AMQ9202: Remote host 'localhost(1414)' not available, retry later.

EXPLANATION: The attempt to allocate a conversation using TCP/IP to host 'localhost(1414)' for channel (Exception) was not successful. However the error may be a transitory one and it may be possible to successfully allocate a TCP/IP conversation later.

For both application I use the same version of amqmdnet.dll : 8.0.0.4

Both programs A and B have the same target framework: 4.5

While testing I didn't tried to run the both applications in the same time and I checked in MQ Explorer if the channel is free (Inactive).

I also tried to change the name of resulting assemblies but with no effect.

Does anyone know what could cause application B to be unable to connect?

When using the hostname localhost networking is still involved, it just all happens inside the one machine. If application A is running in the same machine as your queue manager then having application A connect using the connection name localhost(1414) will certainly work but it is not necessary to make the connection like this (ie using TCP/IP) you could instead make a local bindings connection.

On the other hand, if you are using TCP/IP because application B is running on a different machine to where the queue manager is running, then using localhost(1414) will not work because localhost on one machine does not connect to localhost on another machine. You should change what is specified in the application's connection name from localhost(1414) to use the IP address (or hostname) of the queue manager's machine (followed as before with the port number).

Although I was unable to find the cause of the problem the solution was to simply

delete and re-create the project .

This is what I tried before and what led me to this action:

  • In B I removed and then added back the reference to amqmdnet.dll - not working
  • I created yet another project (let's call it C ): console application, same code - working
  • I renamed* the C project with the same name as B - still working

    *The name of the non-working project contained a dot so I thought that this could cause the problem - it was not the case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM