Package com.rabbitmq.client

Examples of com.rabbitmq.client.ConnectionFactory


  private long DELIVERY_WAIT_TIMEOUT = 3000;

  public void run() {
    _logger.info("started: " + this.getName() + " with params: " + super.toString());
   
    ConnectionFactory factory = new ConnectionFactory();
    factory.setUsername(this.getFetcherQConf().getUserName());
    factory.setPassword(this.getFetcherQConf().getPassword());
    factory.setVirtualHost(this.getFetcherQConf().getVhost());
    factory.setHost(this.getFetcherQConf().getHost());
    factory.setPort(this.getFetcherQConf().getPort());
   
    Connection conn = null;
    Channel channel = null;
    try {
      conn = factory.newConnection();
      // in one thread
      channel = conn.createChannel();
      String exchangeName = getExchange();//"image_admin_exchange";
      String type = this.getType();
      String queueName = getQueue();//"image_admin";
View Full Code Here


    if(cmd.hasOption("h")) {
      formatter.printHelp("RabbitMQProducerMain", options);
      System.exit(2);
    }

    ConnectionFactory factory = new ConnectionFactory();

    if(cmd.hasOption("b")){
      factory.setHost(cmd.getOptionValue("b"));
    }
    if(cmd.hasOption("u")){
      factory.setUsername(cmd.getOptionValue("u"));
    }
    if(cmd.hasOption("p")){
      factory.setPassword(cmd.getOptionValue("p"));
    }
    if(cmd.hasOption("v")){
      factory.setVirtualHost(cmd.getOptionValue("v"));
    }
    if(cmd.hasOption("n")){
      factory.setPort(Integer.parseInt(cmd.getOptionValue("n")));
    }

    String exchange = cmd.getOptionValue("e");
    String routingKey = "default.routing.key";
    if(cmd.hasOption("k")){
      routingKey = cmd.getOptionValue("k");
    }

    boolean durable = cmd.hasOption("d");
    boolean autoDelete = cmd.hasOption("a");
    String type = cmd.getOptionValue("t", "topic");
    boolean single = cmd.hasOption("single");
    int interval = Integer.parseInt(cmd.getOptionValue("interval", "10"));
    int delay = Integer.parseInt(cmd.getOptionValue("delay", "100"));

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Date stop = sdf.parse(cmd.getOptionValue("stop", sdf.format(new Date())));

    Random r = new Random();
    Calendar timer = Calendar.getInstance();
    timer.setTime(sdf.parse(cmd.getOptionValue("start", "2010-01-01T00:00:00")));

    String msg_template = "{\"utcdt\": \"%s\", \"wp\": %d, \"gender\": \"%s\", \"age\": %d}";

    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(exchange, type, durable, autoDelete, null);

    do{
View Full Code Here

    @Override
    public void openConnection() throws IOException {
        super.openConnection();
        if (clusteredConnection == null) {
            try {
                ConnectionFactory cf2 = connectionFactory.clone();
                cf2.setHost("localhost");
                cf2.setPort(5673);
                clusteredConnection = cf2.newConnection();
            }
            catch (IOException e) {
                // Must be no secondary node
            }
        }
View Full Code Here

    }

    // start a connection without capabilities, causing authentication failures
    // to be reported by the broker by closing the connection
    private Connection connectionWithoutCapabilities(String username, String password) throws IOException {
        ConnectionFactory customFactory = connectionFactory.clone();
        customFactory.setUsername(username);
        customFactory.setPassword(password);
        Map<String, Object> customProperties = AMQConnection.defaultClientProperties();
        customProperties.remove("capabilities");
        customFactory.setClientProperties(customProperties);
        return customFactory.newConnection();
    }
View Full Code Here

        customFactory.setClientProperties(customProperties);
        return customFactory.newConnection();
    }

    private void loginOk(String name, byte[][] responses) throws IOException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setSaslConfig(new Config(name, responses));
        Connection connection = factory.newConnection();
        connection.close();
    }
View Full Code Here

                        (start.getVersionMajor() == AMQP.PROTOCOL.MAJOR &&
                                start.getVersionMinor() <= AMQP.PROTOCOL.MINOR));
    }

    public void testCrazyProtocolHeader() throws IOException {
        ConnectionFactory factory = new ConnectionFactory();
        // keep the frame handler's socket
        Socket fhSocket = factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT);
        SocketFrameHandler fh = new SocketFrameHandler(fhSocket);
        fh.sendHeader(100, 3); // major, minor
        DataInputStream in = fh.getInputStream();
        // we should get a valid protocol header back
        byte[] header = new byte[4];
View Full Code Here

            }
        }
    }

    public void testFrameMaxLessThanFrameMinSize() throws IOException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setRequestedFrameMax(100);
        try {
            factory.newConnection();
        }
        catch (IOException ioe) {
            return;
        }
        fail("Broker should have closed the connection since our frame max < frame_min_size");
View Full Code Here

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class ExceptionHandling extends TestCase {
    private ConnectionFactory newConnectionFactory(ExceptionHandler eh) {
        ConnectionFactory cf = new ConnectionFactory();
        cf.setExceptionHandler(eh);
        return cf;
    }
View Full Code Here

            @Override
            public void handleConsumerException(Channel channel, Throwable exception, Consumer consumer, String consumerTag, String methodName) {
                latch.countDown();
            }
        };
        ConnectionFactory cf = newConnectionFactory(eh);
        assertEquals(cf.getExceptionHandler(), eh);
        Connection conn = cf.newConnection();
        assertEquals(conn.getExceptionHandler(), eh);
        Channel ch = conn.createChannel();
        String q = ch.queueDeclare().getQueue();
        ch.basicConsume(q, new DefaultConsumer(ch) {
            @Override
View Full Code Here

        ch.basicPublish("", q, null, "".getBytes());
        wait(latch);
    }

    public void testNullExceptionHandler() {
      ConnectionFactory cf = new ConnectionFactory();
      try {
        cf.setExceptionHandler(null);
        fail("expected setExceptionHandler to throw");
      } catch (IllegalArgumentException iae) {
        // expected
      }
    }
View Full Code Here

TOP

Related Classes of com.rabbitmq.client.ConnectionFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.