RabbitMq安装笔记

教程:

安装:

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() + "]");
		}
	}
posted @ 2017-09-22 16:03  NewSea  阅读(560)  评论(0编辑  收藏  举报