ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexIBM MQ Java / JMSNo connection to IBM MQ via Java

Post new topicReply to topic
No connection to IBM MQ via Java View previous topic :: View next topic
Author Message
Jozef1
PostPosted: Sun Feb 17, 2019 11:31 pm Post subject: No connection to IBM MQ via Java Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Mon Feb 18, 2019 1:49 pm Post subject: Reply with quote

Grand Poobah

Joined: 18 Nov 2003
Posts: 19898
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
View user's profile Send private message Send e-mail
gbaddeley
PostPosted: Mon Feb 18, 2019 2:56 pm Post subject: Reply with quote

Padawan

Joined: 25 Mar 2003
Posts: 1925
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
View user's profile Send private message
RogerLacroix
PostPosted: Tue Feb 19, 2019 8:52 am Post subject: Re: No connection to IBM MQ via Java Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3106
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
View user's profile Send private message Visit poster's website
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexIBM MQ Java / JMSNo connection to IBM MQ via Java
Jump to:



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
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.