ibm-messaging / mq-jms-spring

Components to assist MQ JMS integration with Spring frameworks
Apache License 2.0
189 stars 102 forks source link

Unable to register a JNDI connection factory #108

Closed smaillns closed 5 months ago

smaillns commented 5 months ago

I'm using ibmmq-jms-spring version 3.0.6 with Java 21

I'm having difficulty using my JMS properties to establish a connection to an old IBM MQ server that uses JNDI using the mq-jms-spring-boot-starter

@Configuration
public class JmsConfig {
    @Bean
    public MQQueueConnectionFactory mqConnectionFactory(JmsProperties jmsProperties) throws JMSException {
        MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory();
        mqQueueConnectionFactory.setHostName("x.x.x.x");
        mqQueueConnectionFactory.setChannel("QMX0.SVRC.APPPROMO");
        mqQueueConnectionFactory.setPort(1423);
        mqQueueConnectionFactory.setQueueManager("QMX0");
        return mqQueueConnectionFactory;
    }

    @Bean
    public JmsTemplate jmsTemplate(MQQueueConnectionFactory mqConnectionFactory) {
        JmsTemplate jmsTemplate = new JmsTemplate();
        jmsTemplate.setConnectionFactory(mqConnectionFactory);
        return jmsTemplate;
    }
}

I added this in my application.yml

spring:
  jms:
    jndi-name: java:/jms/queueProlog

but still not able to send a message to the queue

@Slf4j
@Service
public class JMSService {

    @Value("${tpmc.jms.destination-promo-jndi-name}")
    private String destinationPromoJndiName;

    @Autowired
    private JmsTemplate jmsTemplate;

    /**
     * Sending a packet via MQSeries to the Promo queue
     */
    public void sendPromoPacket(final byte[] paquet) throws TechnicalException {
        try {
            log.info("send message to  '{}", this.destinationPromoJndiName);
            jmsTemplate.convertAndSend(this.destinationPromoJndiName, paquet);
        } catch (JmsException e) {
            e.printStackTrace();
            throw new TechnicalException("error sending promo packet ..");
        }
    }
}

I got the following error

2024-04-16T12:58:39.275Z  INFO 1 --- [tpmc1000] [nio-8080-exec-5] c.mypackage.fr.app.storage.JMSService   : send message to  'jms/queuePrologPromo
org.springframework.jms.InvalidDestinationException: JMSWMQ2008: Failed to open MQ queue 'jms/queuePrologPromo'.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2085' ('MQRC_UNKNOWN_OBJECT_NAME').
    at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:280)
    at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:199)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:533)
…
Caused by: com.ibm.msg.client.jakarta.jms.DetailedInvalidDestinationException: JMSWMQ2008: Failed to open MQ queue 'jms/queuePrologPromo'.
JMS attempted to perform an MQOPEN, but IBM MQ reported an error.
Use the linked exception to determine the cause of this error. Check that the specified queue and queue manager are defined correctly.
    at com.ibm.msg.client.jakarta.wmq.common.internal.Reason.reasonToException(Reason.java:513)
    at com.ibm.msg.client.jakarta.wmq.common.internal.Reason.createException(Reason.java:215)
…
Caused by: com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2085' ('MQRC_UNKNOWN_OBJECT_NAME').
    at com.ibm.msg.client.jakarta.wmq.common.internal.Reason.createException(Reason.java:203)
…
2024-04-16T12:58:40.119Z ERROR 1 --- [tpmc1000] [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: com.mypackage.fr.app.exception.TechnicalException: error sending promo packet ..] with root cause

com.mypackage.fr.app.exception.TechnicalException: error sending promo packet ..
    at com.carrefour.fr.tpmc.storage.JMSService.sendPromoPacket(JMSService.java:37) ~[!/:0.0.1-SNAPSHOT]

Here all the provided properties

Queues
    destination-promo-jndi-name: jms/queuePrologPromo
    jndi-queue-factory: jms/prologQF

wmq.hostName=x.x.x.x
wmq.port=1423
wmq.prologQF.channel=QMX0.SVRC.APPPROMO
wmq.prologQF.queueManager=QMX0
wmq.queueProxy.targetClient=MQJMS_CLIENT_NONJMS_MQ
wmq.queueProxy.ccsid=123
wmq.queueProlog.baseQueueName=APP.COMMANDE
wmq.queuePrologPromo.baseQueueName=APP.PROMO
smaillns commented 5 months ago

we don't need the JmsConfig (to be deleted! ) we only need to add the following configuration in application.yml

ibm:
  mq:
    queueManager: QMX0
    channel: QMX0.SVRC.APPPROMO
    connName: @ip(1423).     # x.x.x.x(1423)

and for the queue name we should use APP.PROMO instead It works as a charm (no need for JNDI) ;)