2014-06-09 2 views
1

그래서 rabbitmq 사용법을 이해하는 데 문제가 있습니다. 난 정말 Java 응용 프로그램 등이 실행하기 위해 나는이 호스트를 설정할 수 있습니다 무엇을 이해하지RabbitMQ에 대해 어떤 호스트를 설정해야합니까?

import com.rabbitmq.client.ConnectionFactory; 
import com.rabbitmq.client.Connection; 
import com.rabbitmq.client.Channel; 

public class Send { 
    private final static String QUEUE_NAME = "hello"; 

    public static void main(String[] argv) throws java.io.IOException { 
     // create a connection to the server 
     ConnectionFactory factory = new ConnectionFactory(); 
     factory.setHost("WHAT DO I PUT HERE"); // <==========================What do I put here?? 
     Connection connection = factory.newConnection(); 
     // next we create a channel, which is where most of the API 
     // for getting things done resides 
     Channel channel = connection.createChannel(); 

     // to send we must declare a queue for us to send to; then 
     // we can publish a message to the queue: 
     channel.queueDeclare(QUEUE_NAME, false, false, false, null); 
     String message = "Hello World!"; 
     channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); 
     System.out.println(" [x] Sent '" + message + "'"); 

     channel.close(); 
     connection.close(); 
    } 
} 

: 나는 메시지를 보내 RabbitMQ를 사용하고 다음 Send.java 클래스가 있습니다. 누군가 설명 할 수 있습니까? 감사!

+1

을 당신은 당신의 rabbitMQ 서버가 실행중인 호스트로 설정 – dave

답변

0

이 방법은 연결에 사용할 기본 호스트를 설정합니다. 당신이 당신의 로컬 컴퓨터에 RabbitMQ를 사용하는 경우 당신은 다음과 같이 설정할 수 있습니다 : 또는

factory.setHost("localhost"); 

또는를 :

factory.setHost("127.0.0.1"); 
관련 문제