RabbitMQ-技术调研

  • CMD:

/opt/apps/rabbitmq/sbin/rabbitmq-server   –detached 

/opt/apps/rabbitmq/sbin/rabbitmqctl  stop  

  • web:

http://10.11.156.226:15672/

  • FAQ:
       1.  Rabbitmq Client Automatic Recovery

        ( java, rabbitmq-client-3.3.5.jar )

import java.io.IOException;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;

public class JmsRecvMain {

       public void receive(String[] argv) throws java.io.IOException, java.lang.InterruptedException {

ConnectionFactory factory = new ConnectionFactory();
factory.setHost(JmsUtils.AMMQ_HOST);
factory.setAutomaticRecoveryEnabled(true);
factory.setNetworkRecoveryInterval(10000);

Connection connection = factory.newConnection();
final Channel channel = connection.createChannel();
channel.queueDeclare(JmsUtils.QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

boolean autoAck = false;
channel.basicConsume(JmsUtils.QUEUE_NAME, autoAck, "myConsumerTag",

new DefaultConsumer(channel) {

@Override
public void handleDelivery(String consumerTag,

Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {

// delivery:Body
String message = new String(body);
System.out.println(" [x] Received '" + message + "'");

// delivery:Envelope
System.out.println(" [x] Received Envelope_DeliveryTag'" + envelope.getDeliveryTag() + "'");
System.out.println(" [x] Received Envelope_Exchange'" + envelope.getExchange() + "'");
System.out.println(" [x] Received Envelope_RoutingKey'"+ envelope.getRoutingKey() + "'");
System.out.println(" [x] Received Envelope_Redeliver'"+ envelope.isRedeliver() + "'");
channel.basicAck(envelope.getDeliveryTag(), false);

}});}

public static void main(String[] args) {

try {

new JmsRecvMain().receive(null);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}}}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值