本文整理汇总了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));
}
示例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);
}
示例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);
}
示例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);// 队列会自动删除
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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");
}
}
示例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();
}
示例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));
}