docker直接启动:
docker run --env LICENSE=accept --env MQ_QMGR_NAME=QM1 --volume data:/mnt/mqm --publish 1414:1414 --publish 9443:9443 --detach --env MQ_APP_PASSWORD=passw0rd ibmcom/mq:latest
LICENSE=accept
表示在容器内我们accept mq的licenseMQ_QMGR_NAME=QM1
表示我们创建了一个MQ Server/或叫queue manager,名称为QM1volume
:我们把容器内的目录/mnt/mqm目录印射到volume=qm1data上1414
端口为应用程序通过该端口连接到ibm mq上,因为app可能在本地,所以用-p暴露出来,以便可以在本地连到docker的ibm mq中。9443
端口为ibm mq consoledetach
表示在后台运行MQ_APP_PASSWORD
表示app连接到mq的时候需要通过这个密码
启动后访问:
https://localhost:9443/ibmmq/console/login.html
java集成:
添加maven依赖:
<dependency> <groupId>com.ibm.mq</groupId> <artifactId>mq-jms-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency>
配置文件:
ibm.mq.queueManager=QM1 ibm.mq.channel=DEV.ADMIN.SVRCONN ibm.mq.connName=localhost(1414) ibm.mq.user=admin ibm.mq.password=passw0rd
启动类添加注解:
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.jms.annotation.EnableJms; @SpringBootApplication @EnableJms public class WorkApplication { public static void main(String[] args) { SpringApplication.run(WorkApplication.class, args); } }
发送:
import org.springframework.jms.core.JmsTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; /** * ibm mq 消息发送者 */ @RestController public class SendMessage { @Resource private JmsTemplate jmsTemplate; @GetMapping("send") public boolean convertAndSend() { jmsTemplate.convertAndSend("DEV.QUEUE.1", "Test message, hello ibm mq!"); return true; } }
接收:
import org.springframework.jms.annotation.JmsListener; import org.springframework.jms.listener.adapter.MessageListenerAdapter; import org.springframework.stereotype.Component; /** * ibm mq 消息接受者 */ @Component public class ReceiveMessage extends MessageListenerAdapter { @JmsListener(destination = "DEV.QUEUE.1") public void receiveMessage(String data) { System.out.println("Received <" + data + ">"); } }
标签:ibm,--,springframework,mq,org,import,docker From: https://www.cnblogs.com/goPush/p/17165265.html