简体   繁体   English

如何创建单独的 JMS 消费者和发布者 spring 引导应用程序?

[英]How to create separate JMS consumer and publisher spring boot application?

I am working on an consumer application which consumes from external Queue.我正在开发一个从外部队列消费的消费者应用程序。 For publishing messages there is different application.对于发布消息,有不同的应用程序。 Publisher application: I have this interfaces and its implementation -发布者应用程序:我有这个接口及其实现 -

public interface IRequest extends Serializable{
    void setMessageId(String messageId);
    String getMessageId();
   
    
    Long getId();
    void setId(Long id);

   
}

abstract class:摘要 class:

public abstract class MyMessage implements IRequest {
    private String messageId;
    private Long id;
    //and getter and setter for above fields
}

implementation 1实施 1

public class Mymessage1 extends MyMessage{
    //some implementation
}

implementation 2:实施2:

public class Mymessage2 extends MyMessage{
    //some other implementation
}

publisher method发布者方法

public void publishToMessageTopic(IRequest message,String queueName) {
    logger.debug("Publishing message, id {} to MessageLogs Topic", message.getMessageId()); //queueName is "demoQueue"
    jmsTopicTemplate.convertAndSend(queueName, message);

}

this is jms template bean这是 jms 模板 bean

@Bean
public JmsTemplate jmsTemplate() {
    JmsTemplate jmsTemplate = new JmsTemplate(cachingConnectionFactory());
    jmsTemplate.setMessageConverter(messageConverter());
    return jmsTemplate;
}

this is messsage convertor这是消息转换器

@Bean
public MessageConverter messageConverter() {
    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
    converter.setObjectMapper(getObjectMapper());//set object mapper
    converter.setTargetType(MessageType.TEXT);
    converter.setTypeIdPropertyName("_type");
    return converter;
}

Consumer application: has same interface and it's implementation along with same JMS configuration as that of producer.消费者应用程序:具有与生产者相同的接口和实现以及相同的 JMS 配置。 the listner is as follows:监听器如下:

@JmsListener(destination = "demoQueue", concurrency = "15",containerFactory = "jmsListenerContainerFactory")
public void processLogs(@Payload IRequest request) throws Exception {
    //some processing on request.
}

this is listner factory bean:这是监听器工厂 bean:

@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(DefaultJmsListenerContainerFactoryConfigurer configurer) {
    return getJmsListenerContainerFactory(configurer, "10"); // default container
}

When I try to publish the message from publisher application it successfully publishes but on consumer side I can see exception as follows:当我尝试从发布者应用程序发布消息时,它成功发布但在消费者方面我可以看到如下异常:

nested exception is org.springframework.jms.support.converter.MessageConversionException: Failed to resolve type id [com.model.Mymessage1]; nested exception is java.lang.ClassNotFoundException: com.model.Mymessage1

How do I resolve this issue?我该如何解决这个问题?

You are going to need a package that is common to both projects.您将需要两个项目通用的 package。 This would typically include interfaces and implementation classes.这通常包括接口和实现类。 Your consumer has to know about com.model.Mymessage1 , or am I missing something here?您的消费者必须知道com.model.Mymessage1 ,或者我在这里遗漏了什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring JMS消费者应用程序 - Spring JMS Consumer Application 无法使用 JmsListenerEndpointRegistry 在 Spring Boot 中停止 JMS 使用者 - Not able to stop a JMS consumer in Spring Boot with JmsListenerEndpointRegistry 使用JmsListenerConfigurer的Spring Boot持久JMS使用者 - Spring Boot Durable JMS Consumer using JmsListenerConfigurer 如何在单独的spring集成应用程序中实现JMS入站和出站配置? - How to implement the JMS Inbound & Outbound configuration in separate spring integration application? 如何使用Java Spring Boot应用程序制作持久性JMS消息? - how to make persistent JMS messages with java spring boot application? 无法在 Spring 引导中停止 IBM MQ JMS 使用者 - Not able to stop an IBM MQ JMS consumer in Spring Boot 如何为python发送者创建spring boot rabbitmq使用者? - How to create a spring boot rabbitmq consumer for a python sender? 使用单独的application.properties创建Spring Boot测试 - Create Spring Boot test with separate application.properties 我们如何从同一个 Spring Boot 应用程序创建两个独立的 cassandra 集群? - How can we create two separate cassandra clusters from the same Spring Boot application? Spring JMS生产者和消费者交互 - Spring JMS Producer and Consumer interaction
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM