如何解决Rabbitmq 根据用户数量动态创建队列
我有一个场景,我必须将我收到的消息列表路由到各个用户。 假设如果我有
org.springframework.context.support.AbstractApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emp' defined in class path resource [beans.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'id' of bean class [com.avi.spring.firstspring.employee]: Bean property 'id' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emp' defined in class path resource [beans.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'id' of bean class [com.avi.spring.firstspring.employee]: Bean property 'id' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.applyPropertyValues(AbstractAutowireCapablebeanfactory.java:1711)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.populateBean(AbstractAutowireCapablebeanfactory.java:1426)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:592)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:515)
at org.springframework.beans.factory.support.Abstractbeanfactory.lambda$doGetBean$0(Abstractbeanfactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:318)
at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:199)
at org.springframework.beans.factory.support.DefaultListablebeanfactory.preInstantiateSingletons(DefaultListablebeanfactory.java:847)
at org.springframework.context.support.AbstractApplicationContext.finishbeanfactoryInitialization(AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.context.support.ClasspathXmlApplicationContext.<init>(ClasspathXmlApplicationContext.java:144)
at org.springframework.context.support.ClasspathXmlApplicationContext.<init>(ClasspathXmlApplicationContext.java:85)
at com.avi.spring.firstspring.test.main(test.java:9)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'id' of bean class [com.avi.spring.firstspring.employee]: Bean property 'id' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:243)
at org.springframework.beans.AbstractnestablePropertyAccessor.processLocalProperty(AbstractnestablePropertyAccessor.java:426)
at org.springframework.beans.AbstractnestablePropertyAccessor.setPropertyValue(AbstractnestablePropertyAccessor.java:278)
at org.springframework.beans.AbstractnestablePropertyAccessor.setPropertyValue(AbstractnestablePropertyAccessor.java:266)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:97)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:77)
at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.applyPropertyValues(AbstractAutowireCapablebeanfactory.java:1707)
... 13 more
producer.js
messages = [
{ text: 'hi',user_id: 1 },{ text: 'hi',user_id: 2 },user_id: 3 },user_id: 4 },user_id: 5 },];
consumer.js
var amqp = require('amqplib/callback_api');
amqp.connect('amqps://dgszsgqj:C_wg8fkFrcl6ukZjxBjCcpgc_Pa2j-r9@snake.rmq2.cloudamqp.com/dgszsgqj',function(error0,connection) {
if (error0) {
throw error0;
}
connection.createChannel(function(error1,channel) {
if (error1) {
throw error1;
}
var exchange = 'messages';
channel.assertExchange(exchange,'direct',{
durable: false
});
messages = [
{ text: 'hi',];
messages.map(message=>{
channel.publish(exchange,message.user_id+'',message.text);
})
});
});
我在博客中读到动态创建队列是一种反模式。 https://derickbailey.com/2015/09/02/rabbitmq-best-practices-for-designing-exchanges-queues-and-bindings/
我也尝试在生产者端创建队列,这是创建队列,但无法使用来自该队列的消息,因为我在使用它时不知道队列的名称。
我该如何有效地处理这种情况?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。