I have installed IBMMQ 9.0 in windows running in virtualbox in my local and I have sample java code sending message to MQ.
here is the java code
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
cf.setHostName(MY_IP);
cf.setPort(1417);
cf.setTransportType(WMQConstants.WMQ_CM_CLIENT);
cf.setQueueManager("QM1_TEST");
cf.setChannel("QM1_TEST.CH");
MQQueueConnection connection = (MQQueueConnection)
cf.createQueueConnection();
MQQueueSession session = (MQQueueSession)
connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
MQQueue queue = (MQQueue) session.createQueue("queue:///QUEUE_TEST");
MQQueueSender sender = (MQQueueSender) session.createSender(queue);
String message = "Test Message";
TextMessage textMessage = (TextMessage)
session.createTextMessage(message);
connection.start();
sender.send(textMessage);
The program receives this error.
com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2013: The
security authentication was not valid that was supplied for QueueManager
'QM1_TEST' with connection mode 'Client' and host name '192.168.0.24(1417)'.
Please check if the supplied username and password are correct on the
QueueManager to which you are connecting. at
com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:531)
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:215)
at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:424)
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:8475)
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:7815)
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl._createConnection(JmsConnectionFactoryImpl.java:303)
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:236)
at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6016)
at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:111)
at com.cwt.bpg.cbr.demo.ibm.mq.client.SendMessage.main(SendMessage.java:24)
Caused by: com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2035' ('MQRC_NOT_AUTHORIZED').
at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:203)
... 8 more
Here is the log under my queue manager with significant details.
5/21/2018 16:42:46 - Process(4984.8) User(MUSR_MQADMIN) Program
(amqrmppa.exe) Host(MSEDGEWIN10) Installation(Installation1) VRMF(9.0.0.0)
QMgr(QM1_DEV) AMQ9776: Channel was blocked by userid
EXPLANATION:
The inbound channel 'QM1_DEV.CH' was blocked from address '10.xx.xx.xx'
because the active values of the channel were mapped to a userid which
should be blocked. The active values of the channel were 'MCAUSER(IEUser)
CLNTUSER(IEUser) ADDRESS(LWPHL1U012FXP)'
You are not providing a user and password, your are connecting with the default user identity.
QueueConnection createQueueConnection()
Creates a queue connection with default user identity.
You can either provide credentials:
QueueConnection createQueueConnection(String userid,String password)
By default the userid and password for any user in the mqm group on the MQ broker will have access to the queue managers.
The IBM MQ docs also have instructions for disabling security altogether.
Related
We are trying to connect to IBM MQ from a Java client. We have generated .bindings for JNDI context using the JMSAdmin utility. When connecting to IBM MQ we are getting following exception:
ERR fmbaJMS JMSException: JMSWMQ0018: Failed to connect to queue manager '<queue manager name>' with connection mode 'Client' and host name 'null'
Host name parameter sent is null while .bindings file correctly have
mq/RefAddr/30/Content=localhost(51410)
mq/RefAddr/30/Type=CRSHOSTS
Entries pointing to localhost and port 51410.
Your .bindings file does not look right. What was the JMSAdmin command you used to create it?
MQ0018: Failed to connect to queue manager 'bt.qm.ccxp0'
Is that your queue manager name or QCF? Note: As per the IBM Best Practises, queue manager names should be in uppercase.
To define a QCF (Queue Connection Factory), you would do:
DEFINE QCF(myQCF) QMANAGER(MQA1) CHANNEL(TEST.CHL) HOSTNAME(127.0.0.1) PORT(1414) TRANSPORT(CLIENT) FAILIFQUIESCE(YES)
To define a JMS queue, you would do:
DEFINE Q(mqs.dev.test.q) QUEUE(TEST.Q1) QMANAGER(MQA1) TARGCLIENT(JMS) FAILIFQUIESCE(YES)
Then in your code, you would do the following to load the objects from the MQ JNDI:
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:/C:/JNDI-Directory");
Context ctx = new InitialContext(env);
QueueConnectionFactory cf = (QueueConnectionFactory) ctx.lookup("myQCF");
Queue q = (Queue) ctx.lookup("mqs.dev.test.q");
I am using following code for creating publisher every time when i need to add message in topic i will run this , but some time it gives error
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://" + ip + ":" + port );
connection = connectionFactory.createConnection();
connection.setClientID(publisherName);
PooledConnectionFactory pf = new PooledConnectionFactory(connectionFactory);
pf.setMaxConnections(1000);
Session session = connection.createSession(false,session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(TopicName);
MessageProducer messageProducer = session.createProducer(topic);
Error:
javax.jms.InvalidClientIDException: Broker: localhost - Client: AthenaPublisher already connected from tcp://127.0.0.1:44448
Using a pool when setting the client ID will inevitably lead to such errors as you can have only one connection with a given client ID connected to the broker at any given time. In your case you are configuring the pool for 1000 pooled connections so it will happen pretty often that a new connection will be created and the error you've given will be produced. You need to either not use pooling or use a pool with only 1 pooled connection that shares session level resources with you code.
I need to receive messages of a queue, but this queue is inside in another machine(AWS instance) with https(https://www.mymachine.com/rabbitmq) but when I want to establish a connection to the queue I get a NullPointerException.
This is a part of code:
factory.setHost(https://www.mymachine.com/rabbitmq);
Connection connection = factory.newConnection();
channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
queueName = channel.queueDeclare().getQueue();
channel.queueBind(queueName, EXCHANGE_NAME, "");
RabbitMQ, by default, does not use HTTP protocol, it uses AMQP protocol.
you have to change the factory.setHost with the ip or hostname.
factory.setHost(yourmachine)
if you need an SSL connection please read:
https://www.rabbitmq.com/ssl.html it is very clear tutorial.
The JMS Hello World example shows producers and consumers sending and consuming messages; this is how they seem to create the connection:
ConnectionFactory cf = new com.sun.messaging.ConnectionFactory();
Connection connection = cf.createConnection();
How specify the address and parameters of the remote JMS server?
I want to create an encrypted and compressed connection to an OpenMQ server that is running on another machine. Ideally I would like to use both client and server authentication.
This post seems to provide an example using JMS server address.
This is how it creates a connection. They provide the address and also username and password (admin).
String addressList = "http://127.0.0.1:8080/imqhttp/tunnel";
com.sun.messaging.TopicConnectionFactory topicConnectionFactory = new com.sun.messaging.TopicConnectionFactory();
topicConnectionFactory.setProperty(com.sun.messaging.ConnectionConfiguration.imqAddressList, addressList);
javax.jms.Topic top;
javax.jms.Connection con = topicConnectionFactory.createTopicConnection("admin", "admin");
Where should I set MQMD message context in client WebsphereMQ?
MQQueueConnectionFactory mqConnectionFactory = new MQQueueConnectionFactory();
mqConnectionFactory.setHostName(producerProperties.getProperty("wmq.host"));
mqConnectionFactory.setPort(Integer.valueOf(producerProperties.getProperty("wmq.port")));
mqConnectionFactory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
mqConnectionFactory.setQueueManager(producerProperties.getProperty("wmq.manager"));
mqConnectionFactory.setChannel("MyChannel");
/**
* Producer Section
*/
// Getting producer connection from the MQ server and starting it
Connection producerConnection = mqConnectionFactory.createConnection();
System.out.println("Going to start the producer connection...");
producerConnection.start();
// JMS messages are sent and received using a Session.
Session producerSession = producerConnection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// Destination represents here our queue(testQ) on the MQ server.
Destination producerDestination = producerSession.createQueue(producerProperties.getProperty("wmq.queue.name"));
// MessageProducer is used for sending messages
MessageProducer producer = producerSession.createProducer(producerDestination1);
//create text message going to send
TextMessage sendingMessage = producerSession.createTextMessage("Hi Welcome");
sendingMessage.setJMSType(queueName);
System.out.println("Sending the message...");
//sending the message
producer.send(sendingMessage);
See the sample program. If you installed to the default location on Windows, it's at:
"C:\Program Files (x86)\IBM\WebSphere MQ\tools\jms\samples\simple\SimpleMQMDWrite.java"
Or on *NIX platforms at:
/opt/mqm/samp/jms/samples/simple/SimpleMQMDWrite.java
Go to the WMQ Information Center and look up JMSX* and JMS_IBM_* selectors.