MQ error 2085 while connecting with remote queue - c#

My .NET code can connect and put a message to a remote queue successfuly. However, the same code does not work with local queue. It throws 2085 error. What different setting should be set in code to make that work with local queue?
Here is my code:
Hashtable queueProperties = new Hashtable();
queueProperties[MQC.HOST_NAME_PROPERTY] = "10.x.x.x";
queueProperties[MQC.PORT_PROPERTY] = 1451;
queueProperties[MQC.CHANNEL_PROPERTY] = "TST1.TRADE.CHANNEL";
try
{
// Attempt the connection
queueManager = new MQQueueManager("MYQUEUEMANAGER", queueProperties);
strReturn = "Connected Successfully";
}
catch (MQException mexc)
{
// TODO: Setup other exception handling
throw new Exception(mexc.Message
+ " ReasonCode: " + mexc.ReasonCode
+ "\n" + GetReason(mexc.ReasonCode), mexc);
}
Here, the code is internally using the IIS user id (application pool user) to connect with MQ because this code is run as part of WCF service.

If you run the mqrc utility you can find out what the error code translates to:
$mqrc 2085
2085 0x00000825 MQRC_UNKNOWN_OBJECT_NAME
This means the queue name you are attempting to open does not exist on the queue manager you are connected to.
I noted that the source you posted does not include any code related to opening the queue. You should check that the queue name you are attempting to open does in fact exist on the queue manager you are connecting to.

Related

Connecting .Net Service to IBM WebSphere `MQRC_CONNECTION_BROKEN` error

We have a .NET framework 4.5.2 service running that connects to a WebSphere MQ Server (v7.5.0.9). Our service needs to connect to a Queue and put a message. It doesn’t need to receive anything after putting the message. We have this set up in a Test and Production environment. We've had this running for a while without any issues. Now we are facing an error only in the Production environments. The same code works fine in the Test environment. But Production is showing very inconstant results and we are unable to recreate the issue anywhere else.
The only way we are currently able to get it working is by restarting the .NET service multiple times until the service is able to connect to all Queue Managers. Every time we restart the service we get a different result. We may start the service and it would not be able to connect to any of the Queue Managers and then we restart again and 2 of the Queue Managers are able to connect. Once the connection has been made it is stable, the service will be able to put messages in any of the Queues without it ever disconnecting.
Some of the things we have tried
Before this issue, we were using the SYSTEM.DEF.SVRCONN channel to connect to the Queue Managers but we have changed that to use a "Server Connection" channel we have created in each Queue Manager. We can see the new channels are in an Active state but only if it is able to make the initial connection.
Originally we were connecting to a Queue Manager, putting a message, and closing the Queue but we were leaving the Queue Manager open. We have tried to Close and Disconnect the Queue Managers after every message but that seemed to make things worse.
The .Net service and Websphere are on the same box but we have tried disabling the windows firewall on the server in case there was something blocking it. That didn’t seem to make a difference either.
My background is in .NET so I'm not very familiar with the WebSphere UI and even less with the CLI. Any ideas on places to look or commands to run to get any insight on what is going on would be helpful.
The only error we get in WebSphere is "CompCode: 2, Reason: 2009" but in the service we are catching the exception, it says "Error Message: MQRC_CONNECTION_BROKEN"
Below is the code used to connect and send a message. We are using the amqmdnet.dll
try
{
properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
properties.Add(MQC.PORT_PROPERTY, port);
properties.Add(MQC.CHANNEL_PROPERTY, channelName);
if (!QueueManagers.ContainsKey(queueManagerName))
{
queueManager = new MQQueueManager(queueManagerName, properties);
QueueManagers[queueManagerName] = queueManager;
}
else
{
queueManager = QueueManagers[queueManagerName];
if (!queueManager.IsConnected)
{
queueManager = new MQQueueManager(queueManagerName, properties);
QueueManagers[queueManagerName] = queueManager;
}
}
queue = queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
message = new MQMessage();
message.ClearMessage();
message.Format = MQC.MQFMT_STRING;
message.Encoding = MQC.MQENC_NATIVE;
message.CorrelationId = MQC.MQCI_NONE;
message.CharacterSet = MQC.MQCCSI_Q_MGR;
message.WriteString(messageString);
queue.Put(message);
}
catch (Exception ex)
{
sentToMQServer = false;
QueueManagers.TryRemove(queueManagerName, out var mgr);
queueManager?.Close();
queueManager?.Disconnect();
if (retry)
SendToMQServer(remoteClient, Message, false);
}
finally
{
message = null;
//QueueManagers.TryRemove(queueManagerName, out var mgr);
if (properties != null)
{
properties.Clear();
properties = null;
}
if (queue != null)
{
queue.Close();
queue = null;
}
//queueManager.Close();
//queueManager.Disconnect();
}

Can't connect to Pusher from .NET application

I am trying to connect to the Pusher service from a .NET application and connecting to the Pusher service is never successful. I have followed step by step how to connect to the service, but nothing happens.
Code:
Pusher pusher = new Pusher("APP KEY", new PusherOptions
{
Encrypted = true,
Cluster = "us2"
});
pusher.Connected += Pusher_Connected;
pusher.ConnectionStateChanged += Pusher_ConnectionStateChanged;
pusher.Error += Pusher_Error;
var state = await pusher.ConnectAsync();
Console.WriteLine($"Current state: {state}");
Console.WriteLine(pusher.Channels.Count);
Console.ReadKey();
NOTES: Obviously I change the APP_KEY for my secret key
The library I use is this: https://github.com/pusher/pusher-http-dotnet
I already managed to connect, the problem was that if I used the "await" to wait to connect or subscribe to a channel, nothing ever happened, but if I did it synchronously, it was possible to connect.

Error Message "Only one usage of each socket address is normally permitted" when starting windowsservice

We use a windowsservice which initializes and starts quartz jobs.
Everything works fine on the application servers so when I start the service, the jobs and triggers get scheduled and execute at the exact start time.
I now tried to install the windows service locally on my pc to test something but when I start it and quartz tries to initialize, the following error message appears in our log files:
only one usage of each socket address is normally permitted
The code where the error occurs is the following:
var properties = SetupDefaultProperties();
properties["quartz.plugin.xml.fileNames"] = "~/quartz_jobs.xml";
properties["quartz.scheduler.exporter.type"] = "Quartz.Simpl.RemotingSchedulerExporter, Quartz";
properties["quartz.scheduler.exporter.port"] = "555";
properties["quartz.scheduler.exporter.bindName"] = "QuartzScheduler";
properties["quartz.scheduler.exporter.channelType"] = "tcp";
properties["quartz.scheduler.exporter.channelName"] = "httpQuartz";
properties["quartz.scheduler.exporter.rejectRemoteRequests"] = "true";
var sf = new StdSchedulerFactory(properties);
return sf.GetScheduler();
Have you experienced something like this before and know how to fix it?
Is something blocking port 555?
Can I just use another port or does it have to be port 555 (UDC/TCP)
You can change the port in your config file (or in your case, in your properties) without any issues. Make sure you update your firewall rules to allow access to it though.

Windows Message Queue, message does not arrive on server

currently I am trying to write something in a transactual message queue on a remote machine:
string queueName = "FormatName:Direct=OS:servername\\private$\\testqueue";
var msgQueue = new MessageQueue(queueName);
var msg = new Message("Some body...");
msgQueue.Send(msg, MessageQueueTransactionType.Single);
My local machine shows me a new message in the outgoing folder (if I pause it), it shows the correct IP and the numbers of messages change to 0, if I unpause it. So I guess the code part is correct.
But it never appears on the target message queue.
Security on the target queue is set to "allow everyone everything".
edit:
End2End Tracing says:
On local machine:
Message with ID {...} queued in DIRECT=OS...
Message sent over network
On server:
Message came over network
But it's still not showing up the in message queue. Any ideas?

C# MQ Api How to fetch message without getting exception in case of empty queue

I have to periodically check messages in a queue within Websphere MQ. I haven't found better approach rather than try getting a message and handle 2033 reason code (which is NO_MSG_AVAILABLE) like this:
try
{
// ...
inQueue.Get(message);
}
catch (MQException exception)
{
if (exception.ReasonCode != 2033)
throw;
}
Is there better way to get message from queue? I think that there might be some openOptions flag that I'm not aware of, that wouldn't throw exception when no message available, but return null instead.
There are three ways to avoid or reduce this polling mechanism.
Here they are in oder of elegance(the higher the better):
MQGET with wait interval UNLIMITED and MQGMO_FAIL_IF_QUIESCING
Get your application be triggered by MQServer
Callback function - new with MQ V7 on both sides
You are missing the MQC.MQGMO_WAIT flag on MQGetMessageOptions.Options. Change it this way:
getOptions = new MQGetMessageOptions {WaitInterval = MQC.MQWI_UNLIMITED, Options = MQC.MQGMO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING}
Please note that this would make the calling thread to be blocked till a message arrives at the queue or some connection exception occurs. MQ has another client called IBM Message Service Client (aka XMS .NET) that provides a JMS specification implementation in .NET. This has a nice little Message Listener which gets automatically invoked whenever a message arrives in a queue. Unlike in the above example, the calling thread will not be blocked when Message Listener is used.
More details on XMS .NET can be found here. Samples are also shipped with MQ and for message listener sample, please refer "SampleAsyncConsumer.cs" source file.
I was getting this. I solved it by putting the Message initiator inside the loop:
_queueManager = new MQQueueManager(Queuemanager, _mqProperties);
MQQueue queue = _queueManager.AccessQueue(
Queuename,
MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INQUIRE);
string xml = "";
while (queue.CurrentDepth > 0)
{
MQMessage message = new MQMessage();
queue.Get(message);
xml = message.ReadString(message.MessageLength);
MsgQueue.Enqueue(xml);
message.ClearMessage();
}
There must be something in the Message internally that errors when reusing it for another get.

Categories