在Java中使用wlp为Java springboot应用程序在Eclipse中使用IBM MQ设置侦听器

问题描述 投票:0回答:1

在Eclipse中使用wlp为Java springboot应用程序在Eclipse中使用IBM MQ设置侦听器

[嗨,我正在尝试在本地eclipse中使用wlp设置侦听器,以下是代码:

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类:

@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;
}

现在,我尝试按照ibm指南在wlp中设置我的server.xml,如下所示:

<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.

我可以做些什么来使听众正常工作

spring-boot ibm-mq websphere-liberty spring-jms server.xml
1个回答
0
投票
[尝试了很多之后,我发现了一个解决方案,该解决方案是在Websphere自由服务器19.0.0.6版中使用springboot和jms在本地设置ibm mq消息侦听器的。我使用了以下步骤来使侦听器正常工作:

  1. 下载资源适配器9.0.0.8-IBM-MQ-Java-InstallRA.jar
© www.soinside.com 2019 - 2024. All rights reserved.