IBM WebSphere MQ安装、集成
2021-02-11 05:17
标签:tcp man 文本 png data- 浏览器 ota ccs 缺省 #简介 IBM MQ(IBM Message Queue)是IBM的一款商业消息中间产品,适用于分布式计算环境或异构系统之中。 消息队列技术是分布式应用间交换信息的一种技术。消息队列可驻留在内存或磁盘上,队列存储消息直到它们被应用程序读走。 #安装 1、官网下载地址:https://www.ibm.com/support/pages/node/318077 2、下载完成之后,创建一个用户,选择组为mqm,如下图所示:
#配置MQ #创建队列管理器 #创建本地队列 #将测试消息放入队列 #验证是否已发送测试消息 #创建服务器连接通道 #检查侦听器 #集成指南 #pom配置 #配置文件 #配置类 #发送消息 #接收消息 IBM WebSphere MQ安装、集成 标签:tcp man 文本 png data- 浏览器 ota ccs 缺省 原文地址:https://www.cnblogs.com/lushichao/p/13046437.html
这样会打开“创建队列管理器”向导。
如果当前值为 1414,那么尝试使用另一个端口号,例如:1415 或 1416。如果此阶段未使用缺省端口号 1414
这样会打开“新建本地队列”向导。
这样会在“内容”视图中列出队列管理器的队列。
这样会打开“放入测试消息”对话框。
系统会清空消息数据字段,并将消息放入队列。
这样会打开“消息”浏览器,显示当前 QUEUE_RECV上的消息列表。
mq:
ibm:
host: 127.0.0.1
#侦听器端口号
port: 8888
#(队列管理器名称)
queue-manager: QM_JACK
#(队列名称)
queue-name: QUEUE_RECV
#(通道名称)
channel: CNN_JACK
#创建的MQ用户
username: Administrator
#创建的MQ用户连接密码
password: 123
receive-timeout: 20000
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.msg.client.wmq.WMQConstants;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.connection.JmsTransactionManager;
import org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter;
import org.springframework.jms.core.JmsOperations;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.transaction.PlatformTransactionManager;
@Configuration
public class JmsConfig {
@Value("${mq.ibm.host}")
private String host;
@Value("${mq.ibm.port}")
private Integer port;
@Value("${mq.ibm.queue-manager}")
private String queueManager;
@Value("${mq.ibm.channel}")
private String channel;
@Value("${mq.ibm.username}")
private String username;
@Value("${mq.ibm.password}")
private String password;
@Value("${mq.ibm.receive-timeout}")
private long receiveTimeout;
@Bean
public MQQueueConnectionFactory mqQueueConnectionFactory() {
MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory();
mqQueueConnectionFactory.setHostName(host);
try {
mqQueueConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
mqQueueConnectionFactory.setCCSID(1208);
mqQueueConnectionFactory.setChannel(channel);
mqQueueConnectionFactory.setPort(port);
mqQueueConnectionFactory.setQueueManager(queueManager);
} catch (Exception e) {
e.printStackTrace();
}
return mqQueueConnectionFactory;
}
@Bean
UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter(MQQueueConnectionFactory mqQueueConnectionFactory) {
UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter = new UserCredentialsConnectionFactoryAdapter();
userCredentialsConnectionFactoryAdapter.setUsername(username);
userCredentialsConnectionFactoryAdapter.setPassword(password);
userCredentialsConnectionFactoryAdapter.setTargetConnectionFactory(mqQueueConnectionFactory);
return userCredentialsConnectionFactoryAdapter;
}
@Bean
@Primary
public CachingConnectionFactory cachingConnectionFactory(UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter) {
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
cachingConnectionFactory.setTargetConnectionFactory(userCredentialsConnectionFactoryAdapter);
cachingConnectionFactory.setSessionCacheSize(500);
cachingConnectionFactory.setReconnectOnException(true);
return cachingConnectionFactory;
}
@Bean
public PlatformTransactionManager jmsTransactionManager(CachingConnectionFactory cachingConnectionFactory) {
JmsTransactionManager jmsTransactionManager = new JmsTransactionManager();
jmsTransactionManager.setConnectionFactory(cachingConnectionFactory);
return jmsTransactionManager;
}
@Bean
public JmsOperations jmsOperations(CachingConnectionFactory cachingConnectionFactory) {
JmsTemplate jmsTemplate = new JmsTemplate(cachingConnectionFactory);
jmsTemplate.setReceiveTimeout(receiveTimeout);
return jmsTemplate;
}
}
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsOperations;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Slf4j
@Component
public class SendMessage {
@Autowired
JmsOperations jmsOperations;
@Value("${mq.ibm.queue-name}")
String queueName;
@PostConstruct
public void send() {
log.info("开始发送IBM WebSphere MQ消息...");
jmsOperations.convertAndSend(queueName, "这是一个IBM WebSphere MQ消息");
}
}
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsOperations;
import org.springframework.jms.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.TextMessage;
@Slf4j
@Component
public class ReceiveMessage extends MessageListenerAdapter {
@Autowired
JmsOperations jmsOperations;
@Override
@JmsListener(destination = "${mq.ibm.queue-name}")
public void onMessage(Message message) {
log.info("接收到IBM WebSphere MQ消息:{}", message.toString());
try {
log.info("IBM WebSphere MQ消息内容为:{}", ((TextMessage) message).getText());
} catch (JMSException e) {
e.printStackTrace();
}
}
}
文章标题:IBM WebSphere MQ安装、集成
文章链接:http://soscw.com/index.php/essay/53897.html