[英]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.