RabbitMQ-技术调研

来源:互联网 发布:java dos 运行命令 编辑:程序博客网 时间:2024/06/06 05:41

  • 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();
}}}

0 0