RabbitMq安装笔记
教程:
- 官网:http://projects.spring.io/spring-amqp/
- 参见 : http://www.cnblogs.com/hongdada/p/7203589.html
- Exchange笔记 : http://blog.csdn.net/ityouknow/article/details/70153640
- http://www.jianshu.com/p/80eefec808e5
安装:
sudo apt-get install erlang-nox
sudo apt-get update
sudo apt-get install rabbitmq-server
vi /usr/lib/rabbitmq/bin/rabbitmqctl exec上面添加 HOME=/var/lib/rabbitmq \
sudo rabbitmq-plugins enable rabbitmq_management
sudo service rabbitmq-server restart
远程访问
http://blog.csdn.net/home_zhang/article/details/52797757
执行命令方式:
./rabbitmqctl list_users
./rabbitmqctl add_user test(用户名) test(密码)
./rabbitmqctl set_user_tags test administrator
./rabbitmqctl add_vhost test
./rabbitmqctl set_permissions -p ${vhost} ${user} ".*" ".*" ".*" //后面三个部分分别是 配置,写,读 权限
./rabbitmqctl list_users
./rabbitmqctl list_vhosts
rabbitmqctl change_password ${Username} ${Newpassword}
远程Web管理方式: http://${ip}:15672
RabbitMq 驱动写的也相当不好。
很多时候使用 Object 类型, 根本不知道是什么鬼,查看源码才知道,原来它需要接收不只一种类型的参数,懒的重载,就写了 Object。 比如:
AmqpTemplate.convertAndSend 可以发送三种类型的消息
- byte[]
- String
- Serializable
原码在:
/home/udi/.m2/repository/org/springframework/amqp/spring-amqp/1.7.3.RELEASE/spring-amqp-1.7.3.RELEASE-sources.jar!/org/springframework/amqp/support/converter/SimpleMessageConverter.java
createMessage
@Override
protected Message createMessage(Object object, MessageProperties messageProperties) throws MessageConversionException {
byte[] bytes = null;
if (object instanceof byte[]) {
bytes = (byte[]) object;
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_BYTES);
}
else if (object instanceof String) {
try {
bytes = ((String) object).getBytes(this.defaultCharset);
}
catch (UnsupportedEncodingException e) {
throw new MessageConversionException(
"failed to convert to Message content", e);
}
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);
messageProperties.setContentEncoding(this.defaultCharset);
}
else if (object instanceof Serializable) {
try {
bytes = SerializationUtils.serialize(object);
}
catch (IllegalArgumentException e) {
throw new MessageConversionException(
"failed to convert to serialized Message content", e);
}
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_SERIALIZED_OBJECT);
}
if (bytes != null) {
messageProperties.setContentLength(bytes.length);
}
return new Message(bytes, messageProperties);
}
SimpleMessageListenerContainer.messageListener 可以接收两种类型:
- MessageListener
- ChannelAwareMessageListener
源码在: /home/udi/.m2/repository/org/springframework/amqp/spring-rabbit/1.7.3.RELEASE/spring-rabbit-1.7.3.RELEASE-sources.jar!/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java
checkMessageListener
protected void checkMessageListener(Object messageListener) {
if (!(messageListener instanceof MessageListener || messageListener instanceof ChannelAwareMessageListener)) {
throw new IllegalArgumentException("Message listener needs to be of type ["
+ MessageListener.class.getName() + "] or [" + ChannelAwareMessageListener.class.getName() + "]");
}
}
作者:NewSea 出处:http://newsea.cnblogs.com/
QQ,MSN:iamnewsea@hotmail.com 如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。 |