Create Queue Manager in a Declared Host - c#

In C#, using IBM WebSphere MQ, I run:
var properties = new Hashtable();
properties.Add(MQC.HOST_NAME_PROPERTY, someHostName);
var queueManager = MQQueueManager(someQueueNameManager, properties);
I get an exception:
System.Exception: Channel and Connection MUST be specified
Obviously, it wants me to specify the channel. But I don't want to specify the channel. Is it important to specify it? I mean, When I run
var queueManager = MQQueueManager(someQueueNameManager);
It works and connects to the local MQ. How can I create an MQQueueManager object that connects to a queue manager in a different host without specifying any channel? If specifying a channel is necessary, please explain why that is the case.

You need a MQI Channel (Server Conn or Server Conn & Client Conn) to connect to a remote queue manager (ie a qmgr running on a remote host) over the network. The channel connects to the qmgr and puts/gets the messages for you. For a local qmgr, you can connect in bindings mode (and that's what you have done). This mode bypasses the network stack and connects to the qmgr using shared memory and semaphores.
This is one of the basic technical concept in IBM MQ. I suggest reading the MQ primer. It's small and covers all you need to know about MQ before using it.
http://www.redbooks.ibm.com/redpapers/pdfs/redp0021.pdf

Related

How to connect Remote RabbitMQ Server

I am going to build application (Asp.net C#) to connect RabbitMQ server which is in another country.
So my question is how to connect that server.
I already installed RabbitMQ Client from NuGet Packages.
Is that needed to run RabbitMQ service in my local machine ?
Need to install RabbitMQ Server in my local machine?
From Client some of the parameters i got like
UserName, Password, HostName, Certificate with private key.
I am curious to know which are the basic steps to connect that server from my localhost application.
Can someone provide blog to refer ?
I already tried with different steps but not able to connect.
string vCertSubjectName = "CN=DevRepo, OU=IT, O=OLX, L=KTM, S=Surrey, C=UK";
ConnectionFactory factory = new ConnectionFactory();
factory.AuthMechanisms = new AuthMechanismFactory[] { new ExternalMechanismFactory() };
factory.HostName = "195.168.0.15";
factory.Port = 5673;
factory.Ssl.Certs = getCertificate(vCertSubjectName);
factory.Ssl.ServerName = System.Net.Dns.GetHostName();
factory.Ssl.Enabled = true;
factory.Ssl.Version = SslProtocols.Tls12;
IConnection connection = factory.CreateConnection();
Error coming like connection.start was never received, likely due to a network timeout."
There are very good simple examples of how to write code to send and receive messages to/from RabbitMQ on their site.
Get those examples; set up a RabbitMQ server on your local network; build the examples and verify they work. Once you know how to send/receive to/from a known instance, you can change the connection properties in your send program to point it to the RabbitMQ instance elsewhere.
I would also suggest you do a ping to the IP address of the foreign RabbitMQ server to get an idea of actual transit times. That should give you some idea if the network timeout is a valid issue.
PS. You will need a valid login and password for the RabbitMQ server before it will accept any messages from you. When you build the example programs above as long as you are on the same physical machine where RabbitMQ is running, you can use the default login and password of guest/guest. By default this will NOT work from another machine due to default security configuration of RabbitMQ.

Test connection to the IBM MQ server every couple of minutes

We are using the IBM.XMS 8.0.0.5 .NET library to connect to the IBM MQ server and create our listeners.
But sometimes the VPN tunnel goes in sleep mode (this happens if one of our servers restarts for example). To prevent this, it is necessary to keep the VPN tunnel 'awake' by sending a network packet through the tunnel.
I looked around but IBM MQ does not have any implementation to test the connection to the server. I need some kind of 'ping' which will keep the tunnel up. But pinging is not allowed, I think they reject ICMP echos.
I am planning to create an async Task which will test the connection regularly depending on a configured interval.
Any advice on this one please?
PS Sometimes the connection falls asleep as I mentioned above. And without knowing anything the system engineer restarts the service which sends a dispose to the IBM server, even a dispose message leads to the connection being back up. And all items on the queue start being consumed by us while the service is being stopped... I need to solve this but I don't have a clue how I can do this.
EDIT
Connection is made and consumers are set up as follows:
var factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
// Create WMQ Connection Factory.
var cf = factoryFactory.CreateConnectionFactory();
// Set the properties
cf.SetStringProperty(XMSC.WMQ_HOST_NAME, _parameters.IbmMqHost);
cf.SetIntProperty(XMSC.WMQ_PORT, _parameters.IbmMqPort);
cf.SetStringProperty(XMSC.WMQ_CHANNEL, _parameters.IbmMqChannel);
cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, _parameters.IbmMqQueueManager);
cf.SetStringProperty(XMSC.USERID, username);
cf.SetStringProperty(XMSC.PASSWORD, pw);
cf.SetIntProperty(XMSC.WMQ_CLIENT_RECONNECT_OPTIONS, XMSC.WMQ_CLIENT_RECONNECT);
// Create connection.
connection = cf.CreateConnection();
connection.ExceptionListener = ExceptionCallback;
session = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
destination = session.CreateQueue(queuename);
consumer = session.CreateConsumer(destination);
consumer.MessageListener = listener;
connection.Start();

Mono crashes while connecting to a sql server with a certain instance name

I created a sql server instance called 'abcd' on my computer but when I try to connect to it I receive a strange error. I am able to connect to my others instances with the same code. Is the instance name causing this error?
Here is my code :
string connectionString = "Server=192.168.1.185\\abcd;" + "Database=test;" + "User ID=sa;" + "Password=bob;";
IDbConnection dbcon;
using (dbcon = new SqlConnection(connectionString))
{
dbcon.Open(); // <-- crashes here
Console.WriteLine("Connected");
}
Crash
Mono does not support names pipes or shared memory for connecting to SQL Server. Please enable the TCP/IP protocol.
What's wierd is that I'm able to connect to my other instances. The only thing that changes is the instance name.
I'm using Xamarin.iOS 9.4.0.0, Xamarin Studio 5.10.1, Mono Framework MDK 4.2.1.102
In SQL server the enabled protocols are configured on a per-instance basis, so the most likely explanation is that the named instance you're trying to connect to doesn't have the TCP/IP protocol enabled.
You can check this by opening the Sql Server Configuration Manager tool and going to SQL Server Network Configuration -> Protocols for {instance name}. Make sure that the TCP/IP protocol is enabled.

IBM.XMS MQ Listener Error 2063 or how to create connection without credentials

I'm trying to implement an MQ Listener in a windows service and I have used the xms mq consumer sample provided in the dotnet folder from the MQ Explorer installation. I am using MQ WebSphere 7.1
If I run their sample solution in console, everything works.
However, in my windows service it fails with MQ Reason Code: 2063.
I'm using these settings for my factory
cf.SetStringProperty(XMSC.WMQ_HOST_NAME, _queueHost);
cf.SetIntProperty(XMSC.WMQ_PORT, Convert.ToInt32(_queuePort));
cf.SetStringProperty(XMSC.WMQ_CHANNEL, "SYSTEM.DEF.SVRCONN");
cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT_UNMANAGED);
cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, _queueChannel);
cf.SetIntProperty(XMSC.WMQ_BROKER_VERSION, 0);
and then this line seems to be failing
IConnection connection = cf.CreateConnection(null,null);
I don't want to provide any user credentials, is that possible?
I've tried changing the CONNECTION_MODE to bindings and getting different errors as well.
Is the sample code only working because I am running it and therefore it is using my local credentials by default? Otherwise I am using the same config in both.
The MQ XMS client is propagating the logged on user to the queue manager, then the QM checks its authority records to determine whether that user can connect and what objects it may access.
You could set the authority records to allow the user currently used to run the service, or you could set the logged on user on the windows service to match an allowed user of the queue manager, or set the MCAUSER property on the server connection channel used to connect to the queue manager, if you use client connection.
Setting the MCAUSER on the server connection channel will allow anyone who can connect to that channel to impersonate the set user, so this should be used with caution, possibly with setting appropriate channel authentication records.
References:
http://www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.msc.doc/xms_rtrouble_tips.html
https://www-01.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.sec.doc/q010530_.htm

Configuring mq websphere 7 with .net

I am trying to connect to a remote queue using c#.
I tried many ways to connect to the remote queue but it always fails with common errors like: MQRC_CHANNEL_CONFIG_ERROR or MQRC_HOST_NOT_AVAILABLE.
What I am doing is this:
string channel = "QM_TEST.SVRCONN";
string hostname = "<serverIp>";
string queueName = "QM_TEST";
string port = 1414;
props.Add(MQC.HOST_NAME_PROPERTY, hostname);
props.Add(MQC.CHANNEL_PROPERTY, channel);
props.Add(MQC.PORT_PROPERTY, port );
props.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
MQQueueManager mqQueue = new MQQueueManager(queueName, props);
I have tried changing this but all failed.
I think that my problem is the server configurations..
can you point me to a full guide to how to configure a server and connect to it with .net?
My problem is connecting to a REMOTE server using .net and not to a local server.
Thank you!
The problem was that the CCSID between the client and the server were different.
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=%2Fcom.ibm.mq.csqzaf.doc%2Fcs12480_.htm
On the client side I had to put
Environment.SetEnvironmentVariable("MQCCSID", "437");
Thats why I got:
MQRC_CHANNEL_CONFIG_ERROR
I'm guessing the problem (or at least a problem) is here:
MQQueue mqQueue = new MQQueueManager(queueName, props);
This should be
queueManager = new MQQueueManager(queueManagerName, properties);
If you have installed the WebSphere MQ client to the default location, there are many sample programs under the following directory:
C:\Program Files (x86)\IBM\WebSphere MQ\tools\dotnet\samples\cs\base\
There are a number of sample programs there for various tasks. If you have the latest V7.1 client installed then you will see the following programs:
SimpleAsyncPut
SimpleClientAutoReconnectGet
SimpleClientAutoReconnectPut
SimpleGet
SimpleMessageProperties
SimplePublish
SimplePut
SimpleReadAhead
SimpleSharingConversation
SimpleSubscribe
SimpleXAGet
SimpleXAPut
There are also WCF and XMS samples.
If you need the client code, please see my response to another SO question here for links.
Update:
Here's the normal diagnostic process.
If the WMQ components were installed by relocating libraries or classes from somewhere else, perform an install using the full vendor-supplied client media. This includes troubleshooting utilities such as trace, dspmqver, etc. It also resolves any library or class mismatch issues.
Use the pre-compiled client programs to test the connection. The amqsputc, amqsgetc and amqsbcgc programs require the MQSERVER environment variable as described here. The Q program from SupportPac MA01 is a separate download but has the advantage of NOT requiring any environment variables, CCDT files or other dependencies.
If the sample programs fail, check the QMgr's error logs at [WMQ install]/qmgrs/[QMgr name]/errors/AMQERR01.LOG for messages. Also check for FDC files and errors in [WMQ install]/errors.
If no errors on the QMgr side, attempt the connection again while using a client-side trace as described here and here.
Most client problems are resolved through installation of the full WMQ client as supplied by IBM. (Conversely that implies most people are installing by grabbing DLL or JAR files.) If the problem persists, error log inspection on the QMgr and client side usually reveals the underlying cause. If these do not work then tracing usually diagnoses the remaining issues.
UPDATE 2:
Per the error messages posted at MQSeries.net, the channel has a security exit set. A security exit is external code that the channel calls out to when starting a channel. There is no way to know what the exit expects or does without having access to the code or docs of the exit. If the exit is written in-house, you'll need to talk to the programmer to figure out what it requires. If the exit is a commercial product then you will need to get the documentation for it.
Alternatively, alter the channel so that SCYEXIT is blank to disable the exit.
The data posted at MQSeries.net was as follows:
MQ9575: DCE Security: failed to get the user's login name.
EXPLANATION:
System call 192.168.50.55 to get the login name of the user running WebSphere
MQ client application process 5 failed with error value -1. This occurred in
security exit function create_cred. The exit will now attempt to open channel
using the DCE default login context.
ACTION:
If you wish to run using the DCE default login context take no action. If you
wish to run using the user's login name as the DCE security exit principal
examine the documentation for the operating system on which you are running MQ
clients and reconfigure the operating system as necessary to allow the
192.168.50.55 call to succeed.
Note that it states the call is failing in the security exit.

Categories

Resources