Package com.rabbitmq.client

Examples of com.rabbitmq.client.Connection


            String message = (args.length > 3) ? args[3] :
                "the time is " + new java.util.Date().toString();

            ConnectionFactory cfconn = new ConnectionFactory();
            cfconn.setUri(uri);
            Connection conn = cfconn.newConnection();

            Channel ch = conn.createChannel();

            if (exchange == null) {
                exchange = "amq.topic";
            } else {
                ch.exchangeDeclare(exchange, "topic");
View Full Code Here


            String exchange = (args.length > 2) ? args[2] : null;
            String queue = (args.length > 3) ? args[3] : null;

            ConnectionFactory cfconn = new ConnectionFactory();
            cfconn.setUri(uri);
            Connection conn = cfconn.newConnection();

            final Channel channel = conn.createChannel();

            if (exchange == null) {
                exchange = "amq.topic";
            } else {
                channel.exchangeDeclare(exchange, "topic");
View Full Code Here

        try {
            String uri = (args.length > 0) ? args[0] : "amqp://localhost";

            ConnectionFactory connFactory = new ConnectionFactory();
            connFactory.setUri(uri);
            Connection conn = connFactory.newConnection();
            final Channel ch = conn.createChannel();

            ch.queueDeclare("Hello", false, false, false, null);
            JsonRpcServer server =
                new JsonRpcServer(ch, "Hello", HelloJsonService.class,
                                  new HelloJsonService() {
View Full Code Here

  static String EXCHANGE = "tracer-exchange";
  static String QUEUE = "tracer-queue";

  public void run(){

    final Connection conn;
    try {
      conn = new ConnectionFactory()
          {{setUri(uri);}}.newConnection();
      Channel setup = conn.createChannel();

      setup.exchangeDeclare(EXCHANGE, "direct");
      setup.queueDeclare(QUEUE, false, false, false, null);
      setup.queueBind(QUEUE,EXCHANGE, "");
     
      setup.close();
    } catch(Exception e){
      e.printStackTrace();
      System.exit(1);
      throw null; // placate the compiler
    }

    for(int i = 0; i < threadCount; i++){
      new Thread(){
        @Override public void run(){
          try {
            Channel ch = conn.createChannel();
            while(true){
                ch.close();
                ch = conn.createChannel();
                ch.basicPublish(
                  EXCHANGE,
                  "", null,
                  new byte[1024 * 1024]
                );
View Full Code Here

            String uri = (args.length > 0) ? args[0] : "amqp://localhost";
            String exchange = (args.length > 1) ? args[1] : "amq.rabbitmq.log";

            ConnectionFactory cfconn = new ConnectionFactory();
            cfconn.setUri(uri);
            Connection conn = cfconn.newConnection();

            Channel ch1 = conn.createChannel();

            String queueName = ch1.queueDeclare().getQueue();
            ch1.queueBind(queueName, exchange, "#");

            QueueingConsumer consumer = new QueueingConsumer(ch1);
View Full Code Here

            ConnectionFactory factory = new ConnectionFactory();
            factory.setRequestedHeartbeat(heartbeatInterval);
            for (int i = 0; i < connectionCount; i++) {
                System.out.println("Starting connection " + i);
                factory.setUri(uri);
                final Connection conn = factory.newConnection();

                for (int j = 0; j < channelPerConnectionCount; j++) {
                    final Channel ch = conn.createChannel();

                    final int threadNumber = i * channelPerConnectionCount + j;
                    System.out.println("Starting " + threadNumber + " " + ch
                            + " thread...");
                    new Thread(new Runnable() {
View Full Code Here

    System.exit(2);
      }

            ConnectionFactory connFactory = new ConnectionFactory();
            connFactory.setUri(uri);
            Connection conn = connFactory.newConnection();

            final Channel ch = conn.createChannel();

            String queueName =
    (requestedQueueName.equals("")
     ? ch.queueDeclare()
     : ch.queueDeclare(requestedQueueName,
View Full Code Here

        System.out.println(clazz.getName() + " : javac v" + getCompilerVersion(clazz) + " on " + javaVersion);
        try {
            boolean silent = Boolean.getBoolean("silent");
            final String uri = (args.length > 0) ? args[0] : "amqp://localhost";
            runConnectionNegotiationTest(uri);
            final Connection conn = new ConnectionFactory(){{setUri(uri);}}.newConnection();
            if (!silent) {
                System.out.println("Channel 0 fully open.");
            }

            new TestMain(conn, silent).run();
View Full Code Here

    public static void runConnectionNegotiationTest(final String uri)
        throws IOException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException
    {

        Connection conn;

        try {
            conn = new TestConnectionFactory(0, 1, uri).newConnection();
            conn.close();
            throw new RuntimeException("expected socket close");
        } catch (IOException e) {}

        ConnectionFactory factory;
        factory = new ConnectionFactory();
        factory.setUsername("invalid");
        factory.setPassword("invalid");
        try {
            factory.setUri(uri);
            conn = factory.newConnection();
            conn.close();
            throw new RuntimeException("expected socket close");
        } catch (IOException e) {}

        factory = new ConnectionFactory();
        factory.setRequestedChannelMax(10);
        factory.setRequestedFrameMax(8192);
        factory.setRequestedHeartbeat(1);
        factory.setUri(uri);
        conn = factory.newConnection();
        checkNegotiatedMaxValue("channel-max", 10, conn.getChannelMax());
        checkNegotiatedMaxValue("frame-max", 8192, conn.getFrameMax());
        checkNegotiatedMaxValue("heartbeat", 1, conn.getHeartbeat());
        conn.close();

        factory = new ConnectionFactory();
        factory.setRequestedChannelMax(0);
        factory.setRequestedFrameMax(0);
        factory.setRequestedHeartbeat(0);
        factory.setUri(uri);
        conn = factory.newConnection();
        checkNegotiatedMaxValue("channel-max", 0, conn.getChannelMax());
        checkNegotiatedMaxValue("frame-max", 0, conn.getFrameMax());
        checkNegotiatedMaxValue("heartbeat", 0, conn.getHeartbeat());
        conn.close();

        conn = new ConnectionFactory(){{setUri(uri);}}.newConnection();
        conn.close();
    }
View Full Code Here

    }

    public static void runConnectionShutdownTests(final String uri)
        throws IOException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException
    {
        Connection conn;
        Channel ch;
        // Test what happens when a connection is shut down w/o first
        // closing the channels.
        conn = new ConnectionFactory(){{setUri(uri);}}.newConnection();
        ch = conn.createChannel();
        conn.close();
        // Test what happens when we provoke an error
        conn = new ConnectionFactory(){{setUri(uri);}}.newConnection();
        ch = conn.createChannel();
        try {
            ch.exchangeDeclare("mumble", "invalid");
            throw new RuntimeException("expected shutdown");
        } catch (IOException e) {
        }
        // Test what happens when we just kill the connection
        conn = new ConnectionFactory(){{setUri(uri);}}.newConnection();
        ch = conn.createChannel();
        ((SocketFrameHandler)((AMQConnection)conn).getFrameHandler()).close();
    }
View Full Code Here

TOP

Related Classes of com.rabbitmq.client.Connection

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.