Hey guys I have an application with spring boot that receives a message from a TIBCO EMS, I perform some operations and finally, I need to send that message to an MQ

I have a class Consumer

In the line @JmsLister I have a destination queue from TIBCO EMS because is who sends the message and when I called a method sendMessage I pass a destination queue from the parameter that is to MQ

@Component
public class ClassConsumer {

    
    @JmsListener(destination = "${jms.destination.queue}", 
            containerFactory = Constants.GENERIC_JMS_EMS_LISTENER_BEAN_NAME)
    public void consumerProcess(String request, @Header(JmsHeaders.ID) String id) {
        
        ValoresDtoIn in = operationService.convertXml(request);
        DatosDto datosDto = operationService.fillObject(in);
        this.operacionService.sendMessage(datosDto, mqConstants.getMqDestiQueue(),id);

    }
}

and when it reaches the sendMessage method it marks the error

This is my class service

  @Service
public class Operations implements OperationsService {

    @Autowired
    @Qualifier(Constants.GENERIC_JMS_TEMPLATE_BEAN_NAME)
    private JmsTemplate jmsTemplate;

    @Override
    public void sendMessage(String message, String destination, String id) {

        ConnectionFactory connectionFactory = this.jmsTemplate.getConnectionFactory();

        if (!Objects.isNull(connectionFactory)) {

            try (Connection connection = connectionFactory.createConnection()) {

                Queue queue = connection.createSession().createQueue(destination);

                this.processorService.setId(id);

                this.jmsTemplate.convertAndSend(queue, message, this.processorService);

            } catch (JMSException ex) {
                LOGGER.error(ex.getMessage(), ex);
            }
        }
    }
}

and I had two classes from configuration, one for TibEms and the other from MQ

to TIBCO

@Configuration
public class TibConnectionConfig {

    
    @Bean(name = Constants.GENERIC_CONNECTION_FACTORY_BEAN_NAME)
    public TibjmsConnectionFactory tibjmsConnectionFactory() throws JMSException {

        TibjmsConnectionFactory tibjmsConnectionFactory = new TibjmsConnectionFactory();
        tibjmsConnectionFactory.setServerUrl(constants.getGenericHost());
        tibjmsConnectionFactory.setUserName(constants.getGenericUsername());
        tibjmsConnectionFactory.setUserPassword(constants.getGenericPassword());
        tibjmsConnectionFactory.setReconnAttemptTimeout(constants.getGenericReconnAttemptTimeout());
        tibjmsConnectionFactory.setSSLPassword(constants.getCertificatePassword());
        tibjmsConnectionFactory.setSSLTrustedCertificate(constants.getCertificatePath());
        tibjmsConnectionFactory.setSSLEnableVerifyHostName(false);
        return tibjmsConnectionFactory;
    }

    
    @Bean(name = Constants.GENERIC_CACHING_CONNECTION_FACTORY_BEAN_NAME)
    public CachingConnectionFactory cachingConnectionFactory(
            @Qualifier(Constants.GENERIC_CONNECTION_FACTORY_BEAN_NAME) TibjmsConnectionFactory tibjmsConnectionFactory)
            throws JMSException {

        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(tibjmsConnectionFactory());
        cachingConnectionFactory.setSessionCacheSize(constants.getGenericCacheSize());
        return cachingConnectionFactory;
    }

    
    @Bean(name = Constants.GENERIC_JMS_TEMPLATE_BEAN_NAME)
    public JmsTemplate jmsTemplate(
            @Qualifier(Constants.GENERIC_CACHING_CONNECTION_FACTORY_BEAN_NAME) CachingConnectionFactory connection)
            throws JMSException {

        JmsTemplate jmsTemplate = new JmsTemplate(connection);
        jmsTemplate.setDefaultDestinationName(constants.getGenericDestinationQueue());
        jmsTemplate.setReceiveTimeout(constants.getGenericReceiveTimeout());
        jmsTemplate.setDeliveryMode(constants.getGenericDeliverymode());
        jmsTemplate.setSessionAcknowledgeModeName(constants.getSessionMode());
        jmsTemplate.setExplicitQosEnabled(true);
        jmsTemplate.setSessionTransacted(false);
        return jmsTemplate;
    }
    
      @Bean(name = Constants.GENERIC_JMS_EMS_LISTENER_BEAN_NAME)
      public DefaultJmsListenerContainerFactory jmsEmsListenerContainerFactory(
          @Qualifier(Constants.GENERIC_CACHING_CONNECTION_FACTORY_BEAN_NAME) CachingConnectionFactory connection,
          GenericErrorHandler genericErrorHandler) {

        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connection);
        factory.setErrorHandler(genericErrorHandler);
        factory.setConcurrency(Constants.CONCURRENT_CONSTANT);
        return factory;
      }

}

To MQ

@Configuration
public class MqConnectionConfig {
    
    
    @Bean(name = Constants.CONNECTION_FACTORY_BEAN_NAME)
    public MQConnectionFactory mqConnectionFactory() throws JMSException {
        MQConnectionFactory mqConnectionFactory = new MQConnectionFactory();
        mqConnectionFactory.setHostName(constants.getHost());
        mqConnectionFactory.setPort(constants.getPort());
        mqConnectionFactory.setQueueManager(constants.getManager());
        mqConnectionFactory.setChannel(constants.getChannel());
        mqConnectionFactory.setTransportType(constants.getTranspType());

        return mqConnectionFactory;
    }

    @Bean(name = Constants.CACHING_CONNECTION_FACTORY_BEAN_NAME)
    public CachingConnectionFactory cachingConnectionFactory(
            @Qualifier(Constants.CONNECTION_FACTORY_BEAN_NAME) MQConnectionFactory mqConnectionFactory)
                    throws JMSException {

        CachingConnectionFactory cachingConnectionFactory =
                new CachingConnectionFactory(mqConnectionFactory());
        cachingConnectionFactory.setSessionCacheSize(10);

        return cachingConnectionFactory;
    }

    @Bean(name = Constants.TEMPLATE_BEAN_NAME)
    public JmsTemplate jmsTemplate(
            @Qualifier(Constants.CONNECTION_FACTORY_BEAN_NAME) CachingConnectionFactory cachingConnectionFactory)
                    throws JMSException {

        JmsTemplate jmsTemplate = new JmsTemplate(cachingConnectionFactory);
        jmsTemplate.setDefaultDestinationName(constants.getMqDestiQueue);
        jmsTemplate.setReceiveTimeout(constants.getTimeout());
        jmsTemplate.setDeliveryMode(constants.getDeliveryMode());
        jmsTemplate.setSessionAcknowledgeModeName(constants.getSessionMode());
        jmsTemplate.setExplicitQosEnabled(true);
        jmsTemplate.setSessionTransacted(false);

        return jmsTemplate;
    }

    @Bean(name = Constants.EMS_LISTENER_BEAN_NAME)
    public DefaultJmsListenerContainerFactory mqJmsListenerContainerFactory(
            @Qualifier(Constants.CACHING_CONNECTION_FACTORY_BEAN_NAME) CachingConnectionFactory cachingConnectionFactory,
            GenericEmsErrorHandler genericIbmErrorHandler) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(cachingConnectionFactory);
        factory.setErrorHandler(genericIbmErrorHandler);
        factory.setConcurrency(Constants.CONCURRENT_CONSTANT);
        return factory;
    }


}

and when I running the app sends me this error

ErrorHandler, unmanaged exception description: Listener method Consumer.consumerProcess(java.lang.String,java.lang.String)' 
threw exception; nested exception is org.springframework.jms.InvalidDestinationException: Not allowed to create destination;
nested exception is javax.jms.InvalidDestinationException: Not allowed to create destination.

Can anyone help me? What is wrong? I have no idea how to fix the error

0

There are 0 best solutions below