[rabbitmq-discuss] Configuring beyond rabbitmq server on localhost

McMahon, James S (TASC) james.mcmahon at TASC.COM
Fri Jul 27 19:58:15 BST 2012


Francesco, I have set RABBITMQ_NODE_PORT to 8009. Typically when I have been testing using localhost and 5672, I would start rabbitmq using the command

rabbitmq-server -detached

Should I not do that if I have a particular port I wish to listen on?

    I ask because I am getting an exception in my main of EmitLogDirect and ReceiveLogsDirect when I try to send and/or listen to that particular port. Here is my EmitLogDirect code:

package com.tasc.prism.queue;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

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


public class EmitLogDirect {

  private static final String EXCHANGE_NAME = "BRASS_PRISM";

  public static void main(String[] argv) throws Exception {

          String hostName = "localhost";
          int portNumber = 5672;

          if (argv.length < 2 || argv.length == 3 || argv.length > 4){
                  System.err.println("Usage: EmitLogDirect [BRASS Prism unique session ID] [\"your message\"] [rMQ host, optional] [rMQ port #, optional]");
                  System.exit(1);
          }
          else if (argv.length == 2) {
                  hostName = "localhost";
                  portNumber = 5672; // default port that rabbitMQ listens to
          }
          else if  (argv.length == 4) {
                  hostName = argv[2];
                  portNumber = Integer.parseInt(argv[3]);
          }


          ConnectionFactory factory = new ConnectionFactory();
          factory.setHost(hostName);
          factory.setPort(portNumber);
          Connection connection = factory.newConnection();
          Channel channel = connection.createChannel();

          //channel.exchangeDeclare(EXCHANGE_NAME, "direct");

          String exchange = getExchange(argv);
          String message = getMessage(argv);

          channel.basicPublish(EXCHANGE_NAME, exchange, null, message.getBytes());
          System.out.println(" [x] Sent '" + exchange + "':'" + message + "'");

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

  private static String getExchange(String[] strings){
    if (strings.length < 1)
     return "info";
    return strings[0];
  }

  private static String getMessage(String[] strings){
    if (strings.length < 2)
     return "Hello World!";
    //return joinStrings(strings, " ", 1);
    return strings[1];
  }
}

My rabbitmq hostname is rabbit at PEWTER.

How should I start my rabbitmq-server to be running on port 8009? And what hostname and port should I pass to my EmitLogDirect java class?

Jim
________________________________________
From: rabbitmq-discuss-bounces at lists.rabbitmq.com [rabbitmq-discuss-bounces at lists.rabbitmq.com] on behalf of Francesco Mazzoli [francesco at rabbitmq.com]
Sent: Monday, July 23, 2012 12:13 PM
To: Discussions about RabbitMQ
Subject: Re: [rabbitmq-discuss] Configuring beyond rabbitmq server on   localhost

Hi Jim,
At Mon, 23 Jul 2012 14:29:29 +0000,
McMahon, James S (TASC) wrote:
>      How is this done? I'm guessing that I need to replace all my localhost
> references with some form of a URL for my remote host, and I suspect there
> will be rabbitmq and/or erlang configuration files that need to be modified on
> the server host and client machines so that they can communicate with the
> rabbitmq remote server. Is there an example?

To communicate with a remote rabbit server you need, as you guessed, to specify
the remote host and port when establishing a connection to the broker.  In the
case of the Java client you can do that with the relevant `ConnectionFactory'
methods.

Rabbit will bind on all interfaces by default, so the broker will be accessible
remotely.

>      Do people typically have multiple rabbitMQ servers running in some
>      federated fashion, serving as backup instances for fault tolerance and
>      fail over?

There are various way to cluster/federate rabbit brokers, see
http://www.rabbitmq.com/distributed.html for a comparison between the various
approaches.

--
Francesco * Often in error, never in doubt
_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss at lists.rabbitmq.com
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
CONFIDENTIALITY NOTICE: This message and any attachments or files transmitted with it (collectively, the "Message") are intended only for the addressee and may contain information that is privileged, proprietary and/or prohibited from disclosure by law or contract. If you are not the intended recipient: (a) please do not read, copy or retransmit the Message; (b) permanently delete and/or destroy all electronic and hard copies of the Message; (c) notify us by return email; and (d) you are hereby notified that any dissemination, distribution or copying of the Message is strictly prohibited.


More information about the rabbitmq-discuss mailing list