當前位置: 首頁>>代碼示例>>Java>>正文


Java Channel.queueBind方法代碼示例

本文整理匯總了Java中com.rabbitmq.client.Channel.queueBind方法的典型用法代碼示例。如果您正苦於以下問題:Java Channel.queueBind方法的具體用法?Java Channel.queueBind怎麽用?Java Channel.queueBind使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.rabbitmq.client.Channel的用法示例。


在下文中一共展示了Channel.queueBind方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
@Override
public void run(AppConfiguration configuration, Environment environment) throws Exception {
    SessionFactory sessionFactory = hibernate.getSessionFactory();
    MemoDAO memoDAO = new MemoDAO(sessionFactory);

    QueueConfig queueConfig = configuration.getQueueConfig();
    ConnectionFactory connectionFactory = QueueHelper.getQueue(queueConfig);

    Channel channel = connectionFactory.newConnection().createChannel();

    channel.exchangeDeclare(queueConfig.getExchangeName(), "direct", true);
    channel.queueDeclare(queueConfig.getQueueName(), true, false, false, null);
    channel.queueBind(queueConfig.getQueueName(), queueConfig.getExchangeName(), queueConfig.getRoutingKey());

    channel.basicConsume(queueConfig.getQueueName(), false, "myConsumerTag", new MemoWorker(memoDAO, channel, sessionFactory));

}
 
開發者ID:aytechnologies,項目名稱:heroku-gradle-dropwizard,代碼行數:18,代碼來源:WorkerApplication.java

示例2: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
 * @param args
 * @throws IOException
 * @throws TimeoutException
 * @date 2017年7月13日 下午2:57:32
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	Connection connection = factory.newConnection();
	Channel channel = connection.createChannel();
	// 聲明交換器
	channel.exchangeDeclare(EXCHANGE_NAME_ROUTING, "direct");
	// 獲取匿名隊列名稱
	String queueName = channel.queueDeclare().getQueue();
	// 根據路由關鍵字進行多重綁定
	for (String severity : routingKeys2) {
		channel.queueBind(queueName, EXCHANGE_NAME_ROUTING, severity);
		System.out.println("ReceiveLogsDirect2 exchange:" + EXCHANGE_NAME_ROUTING + ", queue:" + queueName
				+ ", BindRoutingKey:" + severity);
	}
	System.out.println("ReceiveLogsDirect2 Waiting for messages");

	Consumer consumer = new DefaultConsumer(channel) {
		@Override
		public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
				byte[] body) throws UnsupportedEncodingException {
			String message = new String(body, "UTF-8");
			System.out.println("ReceiveLogsDirect2 Received '" + envelope.getRoutingKey() + "':'" + message + "'");
		}
	};
	channel.basicConsume(queueName, true, consumer);

}
 
開發者ID:pudoj,項目名稱:june.mq,代碼行數:40,代碼來源:ReceiveLogsDirect2.java

示例3: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
 * @param args
 * @throws TimeoutException
 * @throws IOException
 * @date 2017年7月13日 下午2:53:18
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	Connection connection = factory.newConnection();
	Channel channel = connection.createChannel();
	// 聲明交換器
	channel.exchangeDeclare(EXCHANGE_NAME_ROUTING, "direct");
	// 獲取匿名隊列名稱
	String queueName = channel.queueDeclare().getQueue();

	// 根據路由關鍵字進行綁定
	for (String routingKey : routingKeys1) {
		channel.queueBind(queueName, EXCHANGE_NAME_ROUTING, routingKey);
		System.out.println("ReceiveLogsDirect1 exchange:" + EXCHANGE_NAME_ROUTING + "," + " queue:" + queueName
				+ ", BindRoutingKey:" + routingKey);
	}
	System.out.println("ReceiveLogsDirect1  Waiting for messages");
	Consumer consumer = new DefaultConsumer(channel) {
		@Override
		public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
				byte[] body) throws IOException {
			String message = new String(body, "UTF-8");
			System.out.println("ReceiveLogsDirect1 Received '" + envelope.getRoutingKey() + "':'" + message + "'");
		}
	};
	channel.basicConsume(queueName, true, consumer);

}
 
開發者ID:pudoj,項目名稱:june.mq,代碼行數:40,代碼來源:ReceiveLogsDirect1.java

示例4: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
 * @param args
 * @throws TimeoutException
 * @throws IOException
 * @date 2017年7月13日 下午2:40:52
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	Connection connection = factory.newConnection();
	Channel channel = connection.createChannel();

	channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

	// 產生一個隨機的隊列名稱
	String queueName = channel.queueDeclare().getQueue();
	channel.queueBind(queueName, EXCHANGE_NAME, "");// 對隊列進行綁定

	System.out.println("ReceiveLogs1 Waiting for messages");
	Consumer consumer = new DefaultConsumer(channel) {
		@Override
		public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
				byte[] body) throws IOException {
			String message = new String(body, "UTF-8");
			System.out.println("ReceiveLogs1 Received '" + message + "'");
		}
	};
	channel.basicConsume(queueName, true, consumer);// 隊列會自動刪除
}
 
開發者ID:pudoj,項目名稱:june.mq,代碼行數:35,代碼來源:ReceiveLogs1.java

示例5: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
	 * @param args
	 * @throws TimeoutException 
	 * @throws IOException 
	 * @date 2017年7月13日 下午3:08:40
	 * @writer junehappylove
	 */
	public static void main(String[] args) throws IOException, TimeoutException {
		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost(host);
		factory.setUsername(username);
		factory.setPassword(password);
		factory.setPort(port);
		factory.setVirtualHost(virtualHost);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
//      聲明一個匹配模式的交換器
        channel.exchangeDeclare(EXCHANGE_NAME_TOPIC, "topic");
        String queueName = channel.queueDeclare().getQueue();
        // 路由關鍵字
        String[] routingKeys = new String[]{"*.*.rabbit", "lazy.#"};
//      綁定路由關鍵字
        for (String bindingKey : routingKeys) {
            channel.queueBind(queueName, EXCHANGE_NAME_TOPIC, bindingKey);
            System.out.println("ReceiveLogsTopic2 exchange:"+EXCHANGE_NAME_TOPIC+", queue:"+queueName+", BindRoutingKey:" + bindingKey);
        }

        System.out.println("ReceiveLogsTopic2 Waiting for messages");

        Consumer consumer = new DefaultConsumer(channel) {
            @Override
			public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
					byte[] body) throws UnsupportedEncodingException  {
                String message = new String(body, "UTF-8");
                System.out.println("ReceiveLogsTopic2 Received '" + envelope.getRoutingKey() + "':'" + message + "'");
            }
        };
        channel.basicConsume(queueName, true, consumer);
	}
 
開發者ID:pudoj,項目名稱:june.mq,代碼行數:40,代碼來源:ReceiveLogsTopic2.java

示例6: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
/**
 * @param args
 * @throws IOException
 * @throws TimeoutException
 * @date 2017年7月13日 下午3:06:20
 * @writer junehappylove
 */
public static void main(String[] args) throws IOException, TimeoutException {
	ConnectionFactory factory = new ConnectionFactory();
	factory.setHost(host);
	factory.setUsername(username);
	factory.setPassword(password);
	factory.setPort(port);
	factory.setVirtualHost(virtualHost);
	Connection connection = factory.newConnection();
	Channel channel = connection.createChannel();

	// 聲明一個匹配模式的交換機
	channel.exchangeDeclare(EXCHANGE_NAME_TOPIC, "topic");
	String queueName = channel.queueDeclare().getQueue();
	// 路由關鍵字
	String[] routingKeys = new String[] { "*.orange.*" };
	// 綁定路由
	for (String routingKey : routingKeys) {
		channel.queueBind(queueName, EXCHANGE_NAME_TOPIC, routingKey);
		System.out.println("ReceiveLogsTopic1 exchange:" + EXCHANGE_NAME_TOPIC + ", queue:" + queueName
				+ ", BindRoutingKey:" + routingKey);
	}
	System.out.println("ReceiveLogsTopic1 Waiting for messages");

	Consumer consumer = new DefaultConsumer(channel) {
		@Override
		public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
				byte[] body) throws IOException {
			String message = new String(body, "UTF-8");
			System.out.println("ReceiveLogsTopic1 Received '" + envelope.getRoutingKey() + "':'" + message + "'");
		}
	};
	channel.basicConsume(queueName, true, consumer);

}
 
開發者ID:pudoj,項目名稱:june.mq,代碼行數:42,代碼來源:ReceiveLogsTopic1.java

示例7: initChannel

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
private void initChannel(Channel channel) throws IOException {
    channel.basicQos(1);
    // this.channel.exchangeDeclare(this.exchange, TOPIC);
    Map<String, Object> args = new HashMap<>();
    args.put("x-expires", 180000); // Three minutes
    channel.queueDeclare(QUEUE_NAME, true, true, true, args);
    channel.queueBind(QUEUE_NAME, NOVA_EXCHANGE, ROUTING_KEY);
    channel.queueBind(QUEUE_NAME, NEUTRON_EXCHANGE, ROUTING_KEY);
    channel.queueBind(QUEUE_NAME, KEYSTONE_EXCHANGE, ROUTING_KEY);
    channel.queueBind(this.queue, this.exchange, this.routingKey);
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:12,代碼來源:RabbitMQClient.java

示例8: setUp

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
	connectionFactory = new ConnectionFactory();
	// connectionFactory.setUri("amqp://guest:[email protected]:" +
	// RABBITMQ_OUTSIDE_PORT + "/");
	connectionFactory.setHost("localhost");
	connectionFactory.setPort(6000);
	connectionFactory.setUsername("guest");
	connectionFactory.setPassword("guest");
	connectionFactory.setVirtualHost("/");

	Connection conn = null;
	Channel channel = null;

	try {
		conn = connectionFactory.newConnection();
		channel = conn.createChannel();
		channel.queueDeclare(TEST_QUEUE, false, false, false, null);
		channel.exchangeDeclare(TEST_QUEUE, "direct");
		channel.queueBind(TEST_QUEUE, TEST_QUEUE, TEST_QUEUE);
	} catch (Exception e) {
		throw new ContextedRuntimeException(e).addContextValue("queueName", TEST_QUEUE)
				.addContextValue("connectionFactory", ToStringBuilder.reflectionToString(connectionFactory));

	}
}
 
開發者ID:BreakTheMonolith,項目名稱:btm-DropwizardHealthChecks,代碼行數:27,代碼來源:RabbitMQHealthCheckTestIntegration.java

示例9: bindQueue

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
private void bindQueue(final Channel channel, final String queueName, final String exchangeName) throws IOException {
    try {
        channel.queueBind(queueName, exchangeName, queueName);
    } catch (final IOException e) {
        s_logger.warn("Failed to bind queue" + e + " on RabbitMQ server");
        throw e;
    }
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:9,代碼來源:RabbitMQEventBus.java

示例10: main

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
	Channel channel = AMQPCommon.connect();
	
	//create the durable exchanges
	channel.exchangeDeclare("flow.fx", "fanout", true);
	channel.exchangeDeclare("orders.dx", "direct", true);
	System.out.println("exchanges created.");

	//create the durable queues
	channel.queueDeclare("book.q", true, false, false, null);
	channel.queueDeclare("music.q", true, false, false, null);
	channel.queueDeclare("movie.q", true, false, false, null);
	channel.queueDeclare("order.q", true, false, false, null);
	channel.queueDeclare("flow.q", true, false, false, null);
	channel.queueDeclare("trade.eq.q", true, false, false, null);
	channel.queueDeclare("trade.1.q", true, false, false, null);
	channel.queueDeclare("trade.2.q", true, false, false, null);
	channel.queueDeclare("workflow.q", true, false, false, null);
	channel.queueDeclare("sync.q", true, false, false, null);
	System.out.println("queues created.");

	//create the bindings
	channel.queueBind("flow.q", "flow.fx", "");
	channel.queueBind("book.q", "orders.dx", "book");
	channel.queueBind("music.q", "orders.dx", "music");
	channel.queueBind("movie.q", "orders.dx", "movie");
	System.out.println("bindings created.");
	
	AMQPCommon.close(channel);
}
 
開發者ID:wmr513,項目名稱:reactive,代碼行數:31,代碼來源:AMQPInitialize.java

示例11: addToQueue

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
private void addToQueue(Long memoId) throws IOException, TimeoutException {
    logger.info("adding a message to queue.");

    Connection connection = null;
    Channel channel = null;
    try {
        connection= connectionFactory.newConnection();
        channel = connection.createChannel();

        channel.exchangeDeclare(queueConfig.getExchangeName(), "direct", true);
        channel.queueDeclare(queueConfig.getQueueName(), true, false, false, null);
        channel.queueBind(queueConfig.getQueueName(), queueConfig.getExchangeName(), queueConfig.getRoutingKey());

        //will send the memoID as the body of message to MQ
        ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES);
        buffer.putLong(memoId);

        channel.basicPublish(queueConfig.getExchangeName(),
                queueConfig.getRoutingKey(),
                false, false, new AMQP.BasicProperties(),
                buffer.array());
        logger.info("message added to queue.");
    }catch(Exception e){
        if (channel!=null){
            channel.close();
        }
        if (connection!=null){
            connection.close();
        }
        logger.error("Error happened.", e);
    }
}
 
開發者ID:aytechnologies,項目名稱:heroku-gradle-dropwizard,代碼行數:33,代碼來源:MemoResource.java

示例12: createListenerContainer

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
@Override
protected Connection createListenerContainer() throws Exception {

    log.debug("Creating connection");
    Connection conn = endpoint.connect(executorService);

    log.debug("Creating channel");
    Channel channel = conn.createChannel();
    // setup the basicQos
    if (endpoint.isPrefetchEnabled()) {
        channel.basicQos(endpoint.getPrefetchSize(), endpoint.getPrefetchCount(),
                        endpoint.isPrefetchGlobal());
    }

    //Let the server pick a random name for us
    DeclareOk result = channel.queueDeclare();
    log.info("Using temporary queue name: {}", result.getQueue());
    setReplyTo(result.getQueue());

    //TODO check for the RabbitMQConstants.EXCHANGE_NAME header
    channel.queueBind(getReplyTo(), endpoint.getExchangeName(), getReplyTo());

    consumer = new RabbitConsumer(this, channel);
    consumer.start();

    return conn;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:28,代碼來源:TemporaryQueueReplyManager.java

示例13: init

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
@Override
public void init(AbstractConfiguration config, ApplicationListenerFactory factory) {
    try {
        ConnectionFactory cf = new ConnectionFactory();
        cf.setUsername(config.getString("rabbitmq.userName", ConnectionFactory.DEFAULT_USER));
        cf.setPassword(config.getString("rabbitmq.password", ConnectionFactory.DEFAULT_PASS));
        cf.setVirtualHost(config.getString("rabbitmq.virtualHost", ConnectionFactory.DEFAULT_VHOST));
        cf.setAutomaticRecoveryEnabled(true);
        cf.setExceptionHandler(new RabbitMQExceptionHandler());
        this.conn = cf.newConnection(Address.parseAddresses(config.getString("rabbitmq.addresses")));
        this.channel = conn.createChannel();

        logger.trace("Initializing RabbitMQ application resources ...");

        APPLICATION_TOPIC = config.getString("communicator.application.topic");
        this.channel.exchangeDeclare(APPLICATION_TOPIC, "topic", true);

        logger.trace("Initializing RabbitMQ application consumer's workers ...");

        Channel consumerChan = this.conn.createChannel();
        consumerChan.queueDeclare(config.getString("rabbitmq.app.queueName"), true, false, true, null);
        consumerChan.queueBind(config.getString("rabbitmq.app.queueName"), APPLICATION_TOPIC, config.getString("rabbitmq.app.routingKey"));
        consumerChan.basicConsume(config.getString("rabbitmq.app.queueName"), true, new RabbitMQApplicationConsumer(consumerChan, factory.newListener()));

    } catch (IOException | TimeoutException e) {
        logger.error("Failed to connect to RabbitMQ servers", e);
        throw new IllegalStateException("Init RabbitMQ communicator failed");
    }
}
 
開發者ID:12315jack,項目名稱:j1st-mqtt,代碼行數:30,代碼來源:RabbitMQApplicationCommunicator.java

示例14: ConsumeChannelImpl

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
ConsumeChannelImpl( Channel delegate, String exchange, String routingKey,int hashCode, ChannelType channelType, DefaultChannelFactory factory) throws IOException {
    super(delegate, hashCode, channelType, factory);
    AMQP.Queue.DeclareOk q = delegate.queueDeclare();
    delegate.queueBind(q.getQueue(), exchange, routingKey);
    this.queue = q.getQueue();
}
 
開發者ID:meltwater,項目名稱:rxrabbit,代碼行數:7,代碼來源:DefaultChannelFactory.java

示例15: declareAndBindQueue

import com.rabbitmq.client.Channel; //導入方法依賴的package包/類
private void declareAndBindQueue(final Channel channel, final String queue, final String exchange, final String routingKey, final Map<String, Object> arguments)
        throws IOException {
    channel.queueDeclare(queue, endpoint.isDurable(), false, endpoint.isAutoDelete(), arguments);
    channel.queueBind(queue, exchange, emptyIfNull(routingKey));
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:6,代碼來源:RabbitMQDeclareSupport.java


注:本文中的com.rabbitmq.client.Channel.queueBind方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。