AMQP--rabbitmq--1
3740 단어 rabbitmq
server 로 나누다 + client
server 설치:
1. 추가 deb http://www.rabbitmq.com/debian/ testing main 에서 / etc / apt / sources. list 까지
2.apt-get update.
3.sudo apt-get install rabbitmq-server
이 단계 가 자동 으로 시 작 됩 니 다. rabbitmq - server 서비스.
상용 명령:
rabbitmqctl -h
rabbitmqctl status
rabbitmqctl stop
rabbitmqctl start_app
클 라 이언 트 설치:
maven:
링크 다운로드:
wget http://www.rabbitmq.com/releases/rabbitmq-java-client/v2.8.4/rabbitmq-java-client-bin-2.8.4.tar.gz
클 라 이언 트 인 코딩 --- 발송 자:
package com.jieting.mq.rabbit.send;
import java.io.IOException;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
public class MessageSend {
private static final String QUENE_NAME = "hello";
public static void main(String[] args) throws IOException {
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setHost("localhost");
Connection newConnection = connectionFactory.newConnection();
Channel createChannel = newConnection.createChannel();
createChannel.queueDeclare(QUENE_NAME, true, false, false, null);
String message = "hello rabbitmq world!";
createChannel.basicPublish("", QUENE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");
createChannel.close();
newConnection.close();
}
}
소비자 코드:
package com.jieting.mq.rabbit.receive;
import java.io.IOException;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.ConsumerCancelledException;
import com.rabbitmq.client.QueueingConsumer;
import com.rabbitmq.client.ShutdownSignalException;
public class MessageReceive {
private static final String QUENE_NAME = "hello";
public static void main(String[] args) throws IOException, ShutdownSignalException, ConsumerCancelledException,
InterruptedException {
ConnectionFactory connectionFactory = new ConnectionFactory();
Connection newConnection = connectionFactory.newConnection();
Channel createChannel = newConnection.createChannel();
createChannel.queueDeclare(QUENE_NAME, true, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
QueueingConsumer queueingConsumer = new QueueingConsumer(createChannel);
createChannel.basicConsume(QUENE_NAME, true, queueingConsumer);
while (true) {
QueueingConsumer.Delivery delivery = queueingConsumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println(" [x] Received '" + message + "'");
}
}
}
이상 의 자 료 는 모두 주소 에서 찾 을 수 있 습 니 다.
http://www.rabbitmq.com/java-client.html
http://www.rabbitmq.com/getstarted.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
RabbitMQ를 사용하여 다음 주차장 시뮬레이션을 비동기식으로 만들려면 어떻게 해야 합니까?Java의 동시성에 대한 다양한 접근 방식을 배우고 이해하려고 합니다. 저는 주차장 시뮬레이션의 직렬화된 구현을 가지고 있습니다. 프로그램이 대신 Rabbitmq를 사용하도록 만들고 싶습니다. 어떻게 해야 합니까? ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.