Настройка приемника с использованием IBM MQ в eclipse с использованием wlp для приложения java springboot - PullRequest
0 голосов
/ 10 января 2020

Настройка прослушивателя с использованием IBM MQ в Eclipse с использованием wlp для java приложения Springboot

Привет, я пытаюсь настроить прослушиватель с использованием wlp в моем локальном файле в Eclipse, следующий код:

pom. xml

   <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jms</artifactId>
        <version>4.3.10.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>javax.jms</groupId>
        <artifactId>javax.jms-api</artifactId>
        <version>2.0</version>
    </dependency>

java class:

@JmsListener(containerFactory = "jmsListenerContainerFactory", destination = test.queue)
public void recieve(Message message)  {
    log.info("inside message receiver");
    try {
        if (message instanceof TextMessage) {
            message.acknowledge();
            String json = ((TextMessage) message).getText();
            /** To solve Json injection fortify issue **/
            String sanitisedJsonMessage = JsonSanitizer.sanitize(json);
            Gson gson = new Gson();
           //business logic
        } else {
            log.error("ERROR ::: invalid message type");
            message.acknowledge();
        }
    } catch (JsonSyntaxException | JMSException  ex) {
        log.error("ERROR: " + ex + ex.getMessage());

    }
}


@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
    ConnectionFactory connectionfactory;
    DefaultJmsListenerContainerFactory listenerFactory;
    try {
        log.info("inside listener factory");
        @Cleanup
        Context context = null;
        listenerFactory = new DefaultJmsListenerContainerFactory();
        context = new InitialContext();
        connectionfactory = (ConnectionFactory) context.lookup(jms/ConnectionFactory);
        listenerFactory.setConnectionFactory(connectionfactory);
        listenerFactory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    } catch (NamingException ex) {
        log.error("ERROR: error looking up queue connection factory jndi {}", ex);
    }
    return listenerFactory;
}

Теперь я попытался настроить свой сервер. xml в wlp согласно рекомендациям IBM, как следующим образом:

<server description="new server">
    <!-- Enable features -->
    <featureManager>
        <feature>javaee-7.0</feature>
        <feature>jndi-1.0</feature>
        <feature>jaxws-2.2</feature>
        <feature>localConnector-1.0</feature>
        <feature>transportSecurity-1.0</feature>
        <feature>servlet-3.1</feature>
        <feature>mdb-3.2</feature>
        <feature>wmqJmsClient-2.0</feature>
        <feature>jsp-2.3</feature>
    </featureManager>

    <!-- Define an Administrator and non-Administrator -->
    <basicRegistry id="basic">
        <user name="admin" password="adminpwd" />
        <user name="nonadmin" password="nonadminpwd" />
    </basicRegistry>

    <!-- Assign 'admin' to Administrator -->
    <administrator-role>
        <user>admin</user>
    </administrator-role>
    <keyStore id="defaultKeyStore" password="Liberty" />


    <httpEndpoint host="*" httpPort="9081" httpsPort="9444"
        id="defaultHttpEndpoint" />



    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true" />
    <applicationMonitor updateTrigger="mbean" />

    <enterpriseApplication
        id="mqtest-ear"
        location="mqtest-ear.ear"
        name="mqtest-ear" />


    <variable name="wmqJmsClient.rar.location"
        value="path\to\wlp\wmq\wmq.jmsra.rar" />

    <jmsQueueConnectionFactory
        jndiName="jms/ConnectionFactory">
        <properties.wmqJms transportType="CLIENT"
            hostName="<test.correcthostname>" port="<test.correctportname>"
            channel="<test.correctchannelname>" queueManager="<test.correctqmgrname>" useSSL="true"
            headerCompression="SYSTEM" messageCompression="RLE"
            sslCipherSuite="SSL_RSA_WITH_AES_256_CBC_SHA256"
            targetClientMatching="true" />
        <connectionManager></connectionManager>
    </jmsQueueConnectionFactory>


    <jmsQueue id="JMSQueue" jndiName="jms/InQueue">
        <properties.wmqJms baseQueueName="test.queue"
            baseQueueManagerName="<test.correctqmgrname>" receiveConversion="CLIENT_MSG"
            putAsyncAllowed="DESTINATION" targetClient="MQ"
            readAheadAllowed="ENABLED" />
    </jmsQueue>


<!--    <resourceAdapter
        location="${wmqJmsClient.rar.location}" id="resourceAdapter">
    </resourceAdapter> -->

    <keyStore id="keyAndTrustStore" password="password"
        location="path\to\keyandtruststore"
        type="PKCS12">
    </keyStore>

Я скачал последний адаптер ресурсов и 9.0.0.8-IBM-MQ- Java -InstallRA.jar. Когда я запускаю приложение, я получаю постоянную ошибку:

2020-01-10 11:21:16 ERROR o.s.j.l.DefaultMessageListenerContainer - Could not refresh JMS Connection for destination 'test.queue' - retrying using FixedBackOff{interval=5000, currentAttempts=12, maxAttempts=unlimited}. Cause: MQJCA1011: Failed to allocate a JMS connection.

что я могу сделать, чтобы заставить слушателя работать

1 Ответ

0 голосов
/ 16 января 2020

После многих попыток и устранения неполадок, я нашел решение для настройки прослушивателя сообщений ibm mq с использованием springboot и jms локально в websphere liberty server version 19.0.0.6. Я использовал следующие шаги, чтобы заставить слушателя работать:

  1. скачать адаптер ресурсов 9.0.0.8-IBM-MQ- Java -InstallRA.jar

  2. Запустите jar, и будет сгенерирована папка с именем wmq с необходимым файлом .rar.

  3. Поместите папку wmq в сервер wlp: путь \ к \ wlp-webProfile8-19.0 .0.6 \ wlp \ usr \ servers \ defaultServer

  4. если вы используете хранилища ключей для ssl, поместите траст и файл ключей .jks или .p12 в путь к серверу wlp \ to \ wlp-webProfile8- 19.0.0.6 \ wlp \ usr \ servers \ defaultServer \ resources \ security

  5. создать новое имя файла jvm.options со следующими данными:

    -Dcom.ibm.mq.cfg.useIBMCipherMappings=false
    -Djavax.net.debug="all"
    -Djdk.tls.client.protocols="TLSv1.2"
    -Dhttps.protocols="TLSv1.2"
    -Djavax.net.ssl.trustStore="path\to\keyandtruststore.jks"
    -Djavax.net.ssl.trustStorePassword="secret"
    -Djavax.net.ssl.keyStore="path\to\keyandtruststore.jks"
    -Djavax.net.ssl.keyStorePassword="secret"
    
  6. сохранить файл в следующем месте: путь \ к \ wlp-webProfile8-19.0.0.6 \ wlp \ usr \ servers \ defaultServer

  7. теперь добавьте необходимые зависимости в pom. xml Я использую весеннюю загрузку версии 2.1.4. Выпуск и следующие важные зависимости, которые потребуются:

    <dependency>
            <groupId>com.ibm.mq</groupId>
            <artifactId>mq-jms-spring-boot-starter</artifactId>
            <version>2.1.2</version>
    </dependency>
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.1.4.RELEASE</version>
    </dependency>
    
  8. теперь изменено Сервер wlp. xml следующим образом:

    <!-- Enable features -->
    <featureManager>
        <feature>webProfile-8.0</feature>
        <feature>localConnector-1.0</feature>
        <feature>jndi-1.0</feature>
        <feature>jaxws-2.2</feature>
        <feature>transportSecurity-1.0</feature>
        <feature>wmqJmsClient-2.0</feature>
        <feature>jsp-2.3</feature>
        <feature>servlet-4.0</feature>
        <feature>jms-2.0</feature>
        <feature>javaee-8.0</feature>
    </featureManager>
    
    <!-- Define an Administrator and non-Administrator -->
    <basicRegistry id="basic">
        <user name="admin" password="adminpwd"/>
        <user name="nonadmin" password="nonadminpwd"/>
    </basicRegistry>
    <!-- Assign 'admin' to Administrator -->
    <administrator-role>
        <user>admin</user>
    </administrator-role>
    
    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>
    <applicationMonitor updateTrigger="mbean"/>
    
    <variable name="wmqJmsClient.rar.location" value="path\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer\wmq\wmq.jmsra.rar"/>
    
    <jmsQueueConnectionFactory jndiName="jms/ConnectionFactory" id="QueueConnectionFactory ">
        <properties.wmqJms channel="channelName" headerCompression="NONE" hostName="host name" messageCompression="RLE" port="1414" queueManager="qmgrName" sslCipherSuite="TLS_RSA_WITH_AES_256_CBC_SHA256" targetClientMatching="true" transportType="CLIENT" temporaryModel="SYSTEM.DEFAULT.MODEL.QUEUE" pollingInterval="5s" rescanInterval="5s"/>
        <connectionManager connectionTimeout="180s" maxPoolSize="20" minPoolSize="1" reapTime="180s" agedTimeout="0" maxIdleTime="30m"/>
    </jmsQueueConnectionFactory>
    
    
    <jmsQueue id="JMSQueue" jndiName="jms/testInQueue">
        <properties.wmqJms putAsyncAllowed="DISABLED" readAheadAllowed="ENABLED" receiveConversion="CLIENT_MSG" targetClient="JMS" baseQueueName="queueName" baseQueueManagerName="qmgrName" failIfQuiesce="true" persistence="APP"/>
    </jmsQueue>
    
    
    <!-- <wmqJmsClient nativeLibraryPath="C:\Users\n78724\CRAS\resource adapter\lib"/> -->
    
    <resourceAdapter id="resourceAdapter"
        location="${wmqJmsClient.rar.location}">
        <customize></customize>
    </resourceAdapter>
    
    <ssl id="keyAndTrustStore" keyStoreRef="defaultKeyStore" sslProtocol="TLSv1.2" trustStoreRef="defaultTrustStore"/>
    <keyStore id="defaultKeyStore" location="path\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer\resources\security\keyandtruststore.jks" password="secret"/>
    <keyStore id="defaultTrustStore" location="path\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer\resources\security\keyandtruststore.jks" password="secret"/>
    
    
    <enterpriseApplication id="Test-ear" location="Test-ear.ear" name="Test-ear"/>
    

  9. запустить сервер

надеюсь, это поможет.

...