Spring boot 如何在Spring Boot中为JMS客户机编写JUnit测试用例

Spring boot 如何在Spring Boot中为JMS客户机编写JUnit测试用例,spring-boot,publish-subscribe,activemq-artemis,jmstemplate,Spring Boot,Publish Subscribe,Activemq Artemis,Jmstemplate,我必须在ActiveMQ Artemis中为我的生产者和消费者编写单元测试。我使用的是发布-订阅模型。我如何编写这两个方面的测试用例 以下是我的制作人代码: @组件 公共类OrderPublisher{ @自动连线 JmsTemplate JmsTemplate; 私有静态最终记录器log=LoggerFactory.getLogger(OrderPublisher.class); @值(${jsa.activemq.topic}) 字符串排序主题; 公共无效sendOrderData(字符串o

我必须在ActiveMQ Artemis中为我的生产者和消费者编写单元测试。我使用的是发布-订阅模型。我如何编写这两个方面的测试用例

以下是我的制作人代码:

@组件
公共类OrderPublisher{
@自动连线
JmsTemplate JmsTemplate;
私有静态最终记录器log=LoggerFactory.getLogger(OrderPublisher.class);
@值(${jsa.activemq.topic})
字符串排序主题;
公共无效sendOrderData(字符串orderData){
log.info(“向队列发送消息”);
convertAndSend(orderTopic,orderData);
}
}
这是我的producer应用程序属性:

spring.jms.pub-sub-domain=true
jsa.activemq.topic=bt-order-queue

spring.artemis.mode=native
spring.artemis.host=localhost
spring.artemis.port=61616
spring.artemis.user=admin
spring.artemis.password=admin
这是我的消费者代码,它在一个单独的项目中

@组件
公共类OrderSubscriber{
私有最终RestTemplate RestTemplate=新RestTemplate();
ObjectMapper ObjectMapper=新的ObjectMapper();
私有静态最终记录器log=LoggerFactory.getLogger(OrderSubscriber.class);
@JmsListener(destination=“${jsa.activemq.topic}”)
public void receiveMessage(字符串顺序)抛出JsonMappingException、JsonProcessingException{
System.out.println(“来自队列的订单数据::”+订单);
}
}
消费者的属性文件:

spring.artemis.mode=native
spring.artemis.host=localhost
spring.artemis.port=61616
spring.artemis.user=admin
spring.artemis.password=admin
spring.jms.pub-sub-domain=true
jsa.activemq.topic=bt-order-queue
这就是我为prodcuer所尝试的:

@RunWith(SpringRunner.class)
@春靴测试
类应用程序测试{
@自动连线
订单出版商;
@统治
public EmbeddedActiveMQResource=new EmbeddedActiveMQResource();
//ActiveMQProducerResource producer=新的ActiveMQProducerResource(resource.getVmURL(),“bt订单队列”);
//ActiveMQConsumerResource消费者=新的ActiveMQConsumerResource(resource.getVmURL(),“bt订单队列”);
@以前
在()之前公开无效{
resource.start();
createQueue(“bt订单队列”);
}
@试验
void contextLoads(){
publisher.sendOrderData(“测试”);
ClientMessage cons=resource.receiveMessage(“bt订单队列”,100000);
System.out.println(“cons::”+cons.toString());
}
}

但是由于我缺乏关于如何编写的信息,我只是想找出一种方法

我的问题是如何为生产者方法和消费者方法编写junit测试用例。我已经编辑了我的原始帖子。到目前为止你尝试了什么?@JustinBertram我已经更新了我为消费者尝试的内容。我无法理解的是嵌入式服务器是如何工作的。如果有合适的样品材料可供选择this@JustinBertram有我可以参考的样品吗。我在这里完全迷路了