spring-boot - 在 Eclipse 中使用 wlp 为 java springboot 应用程序设置使用 IBM MQ 的侦听器
问题描述
在 Eclipse 中使用 wlp 为 java springboot 应用程序设置使用 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.
我该怎么做才能让听众工作
解决方案
经过大量尝试和故障排除后,我找到了在 websphere liberty 服务器版本 19.0.0.6 本地使用 springboot 和 jms 设置 ibm mq 消息侦听器的解决方案。我使用以下步骤使监听器工作:
下载资源适配器 9.0.0.8-IBM-MQ-Java-InstallRA.jar
运行 jar,将生成一个名为 wmq 的文件夹,其中包含所需的 .rar 文件。
将 wmq 文件夹放在 wlp 服务器中: path\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer
如果对 ssl 使用密钥库,请将信任和密钥库 .jks 或 .p12 文件放在 wlp 服务器路径\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer\resources\security 中
使用以下详细信息创建一个新文件名 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"
将文件保存在以下位置:path\to\wlp-webProfile8-19.0.0.6\wlp\usr\servers\defaultServer
现在在 pom.xml 中添加所需的依赖项我使用的是 spring boot 版本 2.1.4.release,以下是需要的重要依赖项:
<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>
现在更改 wlp server.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"/>
启动服务器
希望能帮助到你。
推荐阅读
- python - 如何在 macOS 上的 PyCharm 中使用 Matplotlib.animation.FuncAnimation 显示动画图形?
- c - 为什么这个程序会导致无限循环输出?
- java - 试图创建一个案例来识别多个字符
- css - 我下拉列表中的文本被下面的手风琴隐藏
- java - 为什么我的球在撞到我的左壁和上壁时会融合到它上面?球碰撞程序
- java - 使用 ContextRefreshedEvent 参数为私有方法创建 JUnit
- javascript - Javascript Websocket检查是否没有从服务器收到消息
- vim - .git/tags 文件的 vimrc 标签选项规范
- azure-ad-b2c - 具有动态重定向 uri 和响应类型的 Azure AD B2C 验证链接
- spring-boot - Hystrix 在调用 fallback 后不会终止线程