Приложение IBM MQ JMS с Spring Boot. Получение исключения: сбой вызова IBM MQ '2538' ('MQRC_HOST_NOT_AVAILABLE') - PullRequest
0 голосов
/ 13 апреля 2020

Я пытался создать приложение Spring MQ для загрузки с Spring JMS.

Maven (pom.xml):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE </version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>mqspring</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mqspring</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <webSphereMQVersion>7.5.0.1</webSphereMQVersion>
        <springJMSVersion>4.0.0.RELEASE</springJMSVersion>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>com.ibm.mq</groupId>
            <artifactId>mq-jms-spring-boot-starter</artifactId> 
            <version>2.0.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.jms/jms -->
        <dependency>
            <groupId>javax.jms</groupId>
            <artifactId>jms</artifactId>
            <version>1.1</version>
        </dependency>
         <dependency> 
            <groupId>com.ibm.mq</groupId> 
            <artifactId>com.ibm.mq.allclient</artifactId> 
            <version>9.0.5.0</version> 
        </dependency> 
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <addResources>true</addResources>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Java:

@EnableJms
@SpringBootApplication
public class MqspringApplication {

    @Autowired
    private JmsTemplate jmsTemplate;

    public static void main(String[] args) {
        SpringApplication.run(MqspringApplication.class, args);
    }

}

@PropertySource(ignoreResourceNotFound = true, value = "classpath:application.properties")
@Component
public class MessageSender
{
    @Autowired
    private JmsTemplate jmsTemplate;

    @Value("${ibm.mq.queue}")
    private String destination;

    public void sendMessage() {
        jmsTemplate.send(destination, new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage("ABC");
            }
        });         
    }       
}

@Component
@PropertySource(ignoreResourceNotFound = true, value = "classpath:application.properties")
public class MessageReceiver {

@Autowired
private JmsTemplate jmsTemplate;

    @JmsListener(destination = "ibm.mq.queue")
    public String readMessage() throws JMSException {
        System.out.println("Recieve");
        String message = null;
        Object msg =  jmsTemplate.receiveAndConvert();
        System.out.println("Message:::: "+msg.toString());
        if(msg instanceof TextMessage) {
            message = ((TextMessage) msg).getText();
            System.out.println("Message" + message);
        }

        return message;
    }

}

Config (application.properties):

ibm.mq.queueManager=MQS1
ibm.mq.queue=IDSMQ.REQUEST.FROM.RTPMQ
ibm.mq.hostname=localhost
ibm.mq.port=1415

Тесты:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes  = MqspringApplication.class)
public class SimpleListenerTest {

    @Autowired
    private MessageSender msgService;

    @Autowired
    private MessageReceiver msgReceiver;

    @Test
    public void sendSimpleMessageSender() throws JMSException {
        msgService.sendMessage();       
    }

    @Test
    public void sendSimpleMessageReceiver() throws JMSException {
         msgReceiver.readMessage();         
    }      
}

Когда я выполняю тестовые примеры, я не могу подключиться к IBM MQ. Получение исключения:

org.springframework.jms.IllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'MQS1' with connection mode 'Client' and host name 'localhost(1414)'.; nested exception is com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'MQS1' with connection mode 'Client' and host name 'localhost(1414)'.
Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2538' ('MQRC_HOST_NOT_AVAILABLE').
    at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:274)
    at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:185)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:507)
    at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:584)
    at com.example.mqspring.MessageService.sendMessage(MessageService.java:42)
    at com.example.mqspring.SimpleListenerTest.sendSimpleMessage(SimpleListenerTest.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'MQS1' with connection mode 'Client' and host name 'localhost(1414)'.
Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.
    at com.ibm.msg.client.wmq.common.internal.Reason.reasonToException(Reason.java:489)
    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.MQConnectionFactory.createConnection(MQConnectionFactory.java:6041)
    at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:196)
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494)
    ... 34 more
Caused by: com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2538' ('MQRC_HOST_NOT_AVAILABLE').
    at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:203)
    ... 43 more
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2538;AMQ9204: Connection to host 'localhost(1414)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2538;AMQ9213

Может кто-нибудь, пожалуйста, помогите мне понять, почему я получаю вышеуказанную ошибку. Если я даю порт 1415. Почему он пытается подключиться к localhost (1414)?

Я проверил прослушиватель, LISTENER.TCP работает на порту 1415. Почему не подключается к Queue Manager MQS1?

У меня установлена ​​версия Websphere MQ 7.5.0, но зависимость com.ibm.mq.allclient указывает на версию 9.0.5.0. Это создает какие-либо проблемы?

1 Ответ

0 голосов
/ 13 апреля 2020

hostname и port не являются допустимыми свойствами. Используйте ibm.mq.connName в качестве документации и образцов.

...