|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
No connection to IBM MQ via Java |
« View previous topic :: View next topic » |
Author |
Message
|
Jozef1 |
Posted: Sun Feb 17, 2019 11:31 pm Post subject: No connection to IBM MQ via Java |
|
|
Newbie
Joined: 17 Feb 2019 Posts: 6
|
I'm trying to make an application on Java, which reads a message from the queue. Now with the connection error. If there is an error in authorization, then how to correct it?
Code: |
import com.ibm.mq.jms.JMSC;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.msg.client.wmq.WMQConstants;
import javax.jms.*;
public class Main {
public static void main(String[] args) {
try {
/*MQ Configuration*/
MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory();
mqQueueConnectionFactory.setHostName("localhost");
mqQueueConnectionFactory.setChannel("SVRCONN");//communications link
mqQueueConnectionFactory.setPort(1414);
mqQueueConnectionFactory.setQueueManager("One");//service provider
mqQueueConnectionFactory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
/*Create Connection */
QueueConnection queueConnection = mqQueueConnectionFactory.createQueueConnection();
queueConnection.start();
/*Create session */
QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
/*Create response queue */
Queue queue = queueSession.createQueue("QUEUE.RESPONSE");
/*Create text message */
TextMessage textMessage = queueSession.createTextMessage("put some message here");
textMessage.setJMSReplyTo(queue);
textMessage.setJMSType("mcd://xmlns");//message type
textMessage.setJMSExpiration(2*1000);//message expiration
textMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT); //message delivery mode either persistent or non-persistemnt
/*Create sender queue */
QueueSender queueSender = queueSession.createSender(queueSession.createQueue("QUEUE.REQEST"));
queueSender.setTimeToLive(2*1000);
queueSender.send(textMessage);
/*After sending a message we get message id */
System.out.println("after sending a message we get message id "+ textMessage.getJMSMessageID());
String jmsCorrelationID = " JMSCorrelationID = '" + textMessage.getJMSMessageID() + "'";
/*Within the session we have to create queue reciver */
QueueReceiver queueReceiver = queueSession.createReceiver(queue,jmsCorrelationID);
/*Receive the message from*/
Message message = queueReceiver.receive(60*1000);
String responseMsg = ((TextMessage) message).getText();
queueSender.close();
queueReceiver.close();
queueSession.close();
queueConnection.close();
} catch (JMSException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
} |
Create in IBM MQ 9.1.0.0 command line:
Code: |
1. crtmqm.exe One
2. DEFINE QLOCAL(Q1)
3. DEFINE LISTENER(One.LISTENER) TRPTYPE (TCP) PORT(1414)
4. START LISTENER(One.LISTENER)
5. DEFINE CHANNEL(SYSTEM.ADMIN.SVRCONN) CHLTYPE(SVRCONN) |
Error in IDE IDEA(Java):
Quote: |
Error: com.ibm.msg.client.jms.DetailedJMSSecurityException: JMSWMQ2013: Incorrect credentials passed to the 'One' queue manager in the 'Client' connection mode using the host 'localhost (1414)'.
Verify that the provided username and password are correct at the queue manager you are connecting to. |
Quote: |
Caused by: com.ibm.mq.MQException: JMSCMQ0001: Could not make IBM MQ call; termination code '2' ('MQCC_FAILED'), reason '2035' ('MQRC_NOT_AUTHORIZED'). |
|
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Feb 18, 2019 1:49 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Look up JMSConstants and find the entry for use MQCSP structure (USER_AUTHENTICATION_MQCSP), set that on the connection factory with value true and pass a user name and password when creating the connection:
Code: |
factory.createConnection(userid, password); |
Alternatively use a CCDT and the mqccred exit...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
gbaddeley |
Posted: Mon Feb 18, 2019 2:56 pm Post subject: |
|
|
 Jedi Knight
Joined: 25 Mar 2003 Posts: 2538 Location: Melbourne, Australia
|
Code: |
DEFINE LISTENER(One.LISTENER) TRPTYPE (TCP) PORT(1414) |
If you add CONTROL(QMGR) parameter, the LISTENER object will be automatically started and stopped by the qmgr.
Code: |
DEFINE CHANNEL(SYSTEM.ADMIN.SVRCONN) CHLTYPE(SVRCONN) |
Don't use this channel name, it is bad practice to use any SYSTEM channels in this manner. Use a channel name that is specific for your application. _________________ Glenn |
|
Back to top |
|
 |
RogerLacroix |
Posted: Tue Feb 19, 2019 8:52 am Post subject: Re: No connection to IBM MQ via Java |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
Jozef1 wrote: |
mqQueueConnectionFactory.setChannel("SYSTEM.ADMIN.SVRCONN"); |
First, don't use that channel (probably the reason for 2035). MQ applications should have their own channel. Ask your MQAdmin to create a SVRCONN channel for your application.
i.e. TEST.CHL
Jozef1 wrote: |
Websphere 9.1.0.0 |
Jozef1 wrote: |
QueueConnection queueConnection = mqQueueConnectionFactory.createQueueConnection(); |
Second, if the MQAdmin has turned on the queue manager's CONNAUTH then the queue manager will be performing authentication, so you need to pass a UserId and Password on the connection.
i.e.
Code: |
QueueConnection queueConnection = mqQueueConnectionFactory.createQueueConnection("myUserId", "myPwd"); |
Regards,
Roger Lacroix
Capitalware Inc. _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|