@Override public MessageProducer createProducer(Destination destination) { AMQPDestination dest = (AMQPDestination) destination; return new AMQPMessageProducer(channel, dest.getExchange(), dest.getDestination()); // return new AMQPMessageProducer(channel, exchangeName, ((AMQPDestination) // destination).getDestination()); }
@Override public MessageConsumer createConsumer( Destination destination, String selector, final MessageListener messageListener, Map<String, Object> args) { try { AMQPDestination dest = (AMQPDestination) destination; String routingKey = dest.getDestination(); // as a nicety we declare and bind the queues on the consumer side if the queue is not // temporary if (!dest.isTemporary()) { ConcurrentHashMap<String, Object> p = new ConcurrentHashMap<String, Object>(args); p.putIfAbsent("durable", durableQueue); p.putIfAbsent("exclusive", exclusiveQueue); p.putIfAbsent("autoDelete", autoDeleteQueue); channel.queueDeclare( routingKey, (Boolean) p.remove("durable"), (Boolean) p.remove("exclusive"), (Boolean) p.remove("autoDelete"), args); channel.queueBind( routingKey, exchangeName, routingKey, createBindingArgs(selector + " AND routingKey = " + routingKey)); } DefaultConsumer consumer = new DefaultConsumer(channel) { @Override public void handleDelivery( String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { messageListener.onMessage(new AMQPMessage(body, envelope, properties, channel)); } }; String consumerTag = channel.basicConsume(routingKey, autoAck, consumer); return new AMQPMessageConsumer(dest, consumer, consumerTag); } catch (IOException e) { throw new RuntimeException(e); } }