Пример #1
0
 private Map<String, Object> resolvedExchangeArguments() {
   Map<String, Object> exchangeArgs = new HashMap<>();
   if (endpoint.getExchangeArgsConfigurer() != null) {
     endpoint.getExchangeArgsConfigurer().configurArgs(exchangeArgs);
   }
   return exchangeArgs;
 }
Пример #2
0
 private void declareExchange(
     final Channel channel,
     final String exchange,
     final String exchangeType,
     final Map<String, Object> exchangeArgs)
     throws IOException {
   channel.exchangeDeclare(
       exchange, exchangeType, endpoint.isDurable(), endpoint.isAutoDelete(), exchangeArgs);
 }
Пример #3
0
  private Map<String, Object> populateQueueArgumentsFromDeadLetterExchange(
      final Map<String, Object> queueArgs) {
    if (endpoint.getDeadLetterExchange() != null) {
      queueArgs.put(
          RabbitMQConstants.RABBITMQ_DEAD_LETTER_EXCHANGE, endpoint.getDeadLetterExchange());
      queueArgs.put(
          RabbitMQConstants.RABBITMQ_DEAD_LETTER_ROUTING_KEY, endpoint.getDeadLetterRoutingKey());
    }

    return queueArgs;
  }
Пример #4
0
 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);
   if (shouldBindQueue()) {
     channel.queueBind(queue, exchange, emptyIfNull(routingKey));
   }
 }
Пример #5
0
  private void declareAndBindExchangeWithQueue(final Channel channel) throws IOException {
    if (shouldDeclareExchange()) {
      declareExchange(
          channel,
          endpoint.getExchangeName(),
          endpoint.getExchangeType(),
          resolvedExchangeArguments());
    }

    if (shouldDeclareQueue()) {
      // need to make sure the queueDeclare is same with the exchange declare
      declareAndBindQueue(
          channel,
          endpoint.getQueue(),
          endpoint.getExchangeName(),
          endpoint.getRoutingKey(),
          resolvedQueueArguments());
    }
  }
Пример #6
0
  @Override
  protected RabbitMQEndpoint createEndpoint(
      String uri, String remaining, Map<String, Object> params) throws Exception {
    URI host = new URI("http://" + remaining);
    String hostname = host.getHost();
    int portNumber = host.getPort();
    String exchangeName = ""; // We need to support the exchange to be "" the path is empty
    if (host.getPath().trim().length() > 1) {
      exchangeName = host.getPath().substring(1);
    }

    // ConnectionFactory reference
    ConnectionFactory connectionFactory =
        resolveAndRemoveReferenceParameter(params, "connectionFactory", ConnectionFactory.class);
    @SuppressWarnings("unchecked")
    Map<String, Object> clientProperties =
        resolveAndRemoveReferenceParameter(params, "clientProperties", Map.class);
    TrustManager trustManager =
        resolveAndRemoveReferenceParameter(params, "trustManager", TrustManager.class);
    RabbitMQEndpoint endpoint;
    if (connectionFactory == null) {
      endpoint = new RabbitMQEndpoint(uri, this);
    } else {
      endpoint = new RabbitMQEndpoint(uri, this, connectionFactory);
    }
    endpoint.setHostname(hostname);
    endpoint.setPortNumber(portNumber);
    endpoint.setExchangeName(exchangeName);
    endpoint.setClientProperties(clientProperties);
    endpoint.setTrustManager(trustManager);
    setProperties(endpoint, params);

    if (LOG.isDebugEnabled()) {
      LOG.debug(
          "Creating RabbitMQEndpoint with host {}:{} and exchangeName: {}",
          new Object[] {
            endpoint.getHostname(), endpoint.getPortNumber(), endpoint.getExchangeName()
          });
    }

    return endpoint;
  }
Пример #7
0
 private void declareAndBindDeadLetterExchangeWithQueue(final Channel channel) throws IOException {
   if (endpoint.getDeadLetterExchange() != null) {
     // TODO Do we need to setup the args for the DeadLetter?
     declareExchange(
         channel,
         endpoint.getDeadLetterExchange(),
         endpoint.getDeadLetterExchangeType(),
         Collections.<String, Object>emptyMap());
     declareAndBindQueue(
         channel,
         endpoint.getDeadLetterQueue(),
         endpoint.getDeadLetterExchange(),
         endpoint.getDeadLetterRoutingKey(),
         null);
   }
 }
Пример #8
0
 private void populateQueueArgumentsFromConfigurer(final Map<String, Object> queueArgs) {
   if (endpoint.getQueueArgsConfigurer() != null) {
     endpoint.getQueueArgsConfigurer().configurArgs(queueArgs);
   }
 }
Пример #9
0
 private boolean shouldBindQueue() {
   return !endpoint.isSkipQueueBind();
 }
Пример #10
0
 private boolean shouldDeclareExchange() {
   return !endpoint.isSkipExchangeDeclare();
 }
Пример #11
0
 private boolean shouldDeclareQueue() {
   return !endpoint.isSkipQueueDeclare() && endpoint.getQueue() != null;
 }