org.springframework.amqp.core.Address类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(195)

本文整理了Java中org.springframework.amqp.core.Address类的一些代码示例,展示了Address类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address类的具体详情如下:
包路径:org.springframework.amqp.core.Address
类名称:Address

Address介绍

[英]Represents an address for publication of an AMQP message. The AMQP 0-8 and 0-9 specifications have an unstructured string that is used as a "reply to" address. There are however conventions in use and this class makes it easier to follow these conventions, which can be easily summarised as:

(exchange)/(routingKey)

Here we also the exchange name to default to empty (so just a routing key will work if you know the queue name).
[中]表示用于发布AMQP消息的地址。AMQP 0-8和0-9规范有一个用作“回复”地址的非结构化字符串。然而,使用中有一些约定,此类使遵循这些约定变得更容易,这些约定可以简单地概括为:

(exchange)/(routingKey)

这里我们还将exchange名称默认为空(因此,如果您知道队列名称,只需使用路由键即可)。

代码示例

代码示例来源:origin: spring-projects/spring-integration

String replyToProperty = message.getMessageProperties().getReplyTo();
if (replyToProperty != null) {
  replyTo = new Address(replyToProperty);
  AmqpInboundGateway.this.amqpTemplate.convertAndSend(replyTo.getExchangeName(),
      replyTo.getRoutingKey(), reply.getPayload(), messagePostProcessor);

代码示例来源:origin: spring-projects/spring-amqp

public void setReplyToAddress(Address replyTo) {
  this.replyTo = (replyTo != null) ? replyTo.toString() : null;
}

代码示例来源:origin: spring-projects/spring-amqp

protected void doPublish(Channel channel, Address replyTo, Message message) throws IOException {
  channel.basicPublish(replyTo.getExchangeName(), replyTo.getRoutingKey(), this.mandatoryPublish,
      this.messagePropertiesConverter.fromMessageProperties(message.getMessageProperties(), this.encoding),
      message.getBody());
}

代码示例来源:origin: spring-projects/spring-amqp

@Test
public void parseUnstructuredWithRoutingKeyOnly() {
  Address address = new Address("my-routing-key");
  assertEquals("my-routing-key", address.getRoutingKey());
  assertEquals("/my-routing-key", address.toString());
  address = new Address("/foo");
  assertEquals("foo", address.getRoutingKey());
  assertEquals("/foo", address.toString());
  address = new Address("bar/baz");
  assertEquals("bar", address.getExchangeName());
  assertEquals("baz", address.getRoutingKey());
  assertEquals("bar/baz", address.toString());
}

代码示例来源:origin: spring-projects/spring-integration

/**
 * The {@code defaultReplyTo} address with the form
 * <pre class="code">
 * (exchange)/(routingKey)
 * </pre>
 * or
 * <pre class="code">
 * (queueName)
 * </pre>
 * if the request message doesn't have a {@code replyTo} property.
 * The second form uses the default exchange ("") and the queue name as
 * the routing key.
 * @param defaultReplyTo the default {@code replyTo} address to use.
 * @since 4.2
 * @see Address
 */
public void setDefaultReplyTo(String defaultReplyTo) {
  this.defaultReplyTo = new Address(defaultReplyTo);
}

代码示例来源:origin: spring-projects/spring-amqp

@Test
public void toStringCheck() {
  Address address = new Address("my-exchange", "routing-key");
  String replyToUri = "my-exchange/routing-key";
  Assert.assertEquals(replyToUri, address.toString());
}

代码示例来源:origin: spring-projects/spring-amqp

@Test
public void testReplyTo() throws Exception {
  MessageProperties properties = new MessageProperties();
  properties.setReplyTo("foo/bar");
  assertEquals("bar", properties.getReplyToAddress().getRoutingKey());
}

代码示例来源:origin: org.springframework.amqp/spring-rabbit

protected void doPublish(Channel channel, Address replyTo, Message message) throws IOException {
  channel.basicPublish(replyTo.getExchangeName(), replyTo.getRoutingKey(), this.mandatoryPublish,
      this.messagePropertiesConverter.fromMessageProperties(message.getMessageProperties(), this.encoding),
      message.getBody());
}

代码示例来源:origin: spring-projects/spring-amqp

@Test
public void testEmpty() {
  Address address = new Address("/");
  assertEquals("", address.getExchangeName());
  assertEquals("", address.getRoutingKey());
  assertEquals("/", address.toString());
}

代码示例来源:origin: spring-projects/spring-amqp

public Address getReplyToAddress() {
  return (this.replyTo != null) ? new Address(this.replyTo) : null;
}

代码示例来源:origin: spring-projects/spring-amqp

byte[] bytes = "foo".getBytes();
MessageProperties properties = new MessageProperties();
Address replyTo = new Address("address");
Message message1 = MessageBuilder.withClonedBody(bytes)
    .andProperties(this.setAll(MessagePropertiesBuilder.fromClonedProperties(properties))
        .setReplyToAddress(replyTo)
        .setReplyToAddressIfAbsent(new Address("addressxxxx"))
        .build())
    .build();
assertNotSame(bytes, message1.getBody());
assertTrue(Arrays.equals(bytes, message1.getBody()));
assertEquals(replyTo.toString(), message1.getMessageProperties().getReplyToAddress().toString());
Address foo = new Address("foo");
Message message2 = MessageBuilder.fromClonedMessage(message1)
    .setReplyToAddress(foo)
assertEquals(message1.getMessageProperties(), MessageBuilder.fromMessage(message2)
    .setReplyToAddress(replyTo).build().getMessageProperties());
assertEquals(foo.toString(), message2.getMessageProperties().getReplyToAddress().toString());
assertEquals(replyTo.toString(), message3.getMessageProperties().getReplyToAddress().toString());
    .setReplyToAddressIfAbsent(foo)
    .build();
assertEquals(foo.toString(), message4.getMessageProperties().getReplyToAddress().toString());

代码示例来源:origin: spring-projects/spring-integration

@Test
public void verifyLifeCycle() {
  Object gateway = context.getBean("autoStartFalseGateway");
  assertEquals(Boolean.FALSE, TestUtils.getPropertyValue(gateway, "autoStartup"));
  assertEquals(123, TestUtils.getPropertyValue(gateway, "phase"));
  assertFalse(TestUtils.getPropertyValue(gateway, "messageListenerContainer.missingQueuesFatal", Boolean.class));
  Object amqpTemplate = context.getBean("amqpTemplate");
  assertSame(amqpTemplate, TestUtils.getPropertyValue(gateway, "amqpTemplate"));
  Address defaultReplyTo = TestUtils.getPropertyValue(gateway, "defaultReplyTo", Address.class);
  Address expected = new Address("fooExchange/barRoutingKey");
  assertEquals(expected.getExchangeName(), defaultReplyTo.getExchangeName());
  assertEquals(expected.getRoutingKey(), defaultReplyTo.getRoutingKey());
  assertEquals(expected, defaultReplyTo);
}

代码示例来源:origin: spring-projects/spring-amqp

private void send(Object object, Address replyToAddress, Message requestMessage) {
  Message message = this.messageConverter.toMessage(object, new MessageProperties());
  message.getMessageProperties().setCorrelationId(requestMessage.getMessageProperties().getCorrelationId());
  getAmqpTemplate().send(replyToAddress.getExchangeName(), replyToAddress.getRoutingKey(), message);
}

代码示例来源:origin: spring-projects/spring-amqp

@Test
public void parseWithoutRoutingKey() {
  Address address = new Address("fanout://my-exchange");
  assertEquals("my-exchange", address.getExchangeName());
  assertEquals("", address.getRoutingKey());
  assertEquals("my-exchange/", address.toString());
}

代码示例来源:origin: org.springframework.integration/spring-integration-amqp

/**
 * The {@code defaultReplyTo} address with the form
 * <pre class="code">
 * (exchange)/(routingKey)
 * </pre>
 * or
 * <pre class="code">
 * (queueName)
 * </pre>
 * if the request message doesn't have a {@code replyTo} property.
 * The second form uses the default exchange ("") and the queue name as
 * the routing key.
 * @param defaultReplyTo the default {@code replyTo} address to use.
 * @since 4.2
 * @see Address
 */
public void setDefaultReplyTo(String defaultReplyTo) {
  this.defaultReplyTo = new Address(defaultReplyTo);
}

代码示例来源:origin: spring-projects/spring-amqp

/**
 * Invoked by the container during startup so it can verify the queue is correctly
 * configured (if a simple reply queue name is used instead of exchange/routingKey).
 * @return the queue name, if configured.
 * @since 1.5
 */
@Override
@Nullable
public Collection<String> expectedQueueNames() {
  this.isListener = true;
  Collection<String> replyQueue = null;
  if (this.replyAddress == null || this.replyAddress.equals(Address.AMQ_RABBITMQ_REPLY_TO)) {
    throw new IllegalStateException("A listener container must not be provided when using direct reply-to");
  }
  else {
    Address address = new Address(this.replyAddress);
    if ("".equals(address.getExchangeName())) {
      replyQueue = Collections.singletonList(address.getRoutingKey());
    }
    else {
      if (logger.isInfoEnabled()) {
        logger.info("Cannot verify reply queue because 'replyAddress' is not a simple queue name: "
            + this.replyAddress);
      }
    }
  }
  return replyQueue;
}

代码示例来源:origin: spring-projects/spring-amqp

@Test
public void testDirectReplyTo() {
  String replyTo = Address.AMQ_RABBITMQ_REPLY_TO + ".ab/cd/ef";
  MessageProperties props = new MessageProperties();
  props.setReplyTo(replyTo);
  Message message = new Message("foo".getBytes(), props);
  Address address = message.getMessageProperties().getReplyToAddress();
  assertEquals("", address.getExchangeName());
  assertEquals(replyTo, address.getRoutingKey());
  address = props.getReplyToAddress();
  assertEquals("", address.getExchangeName());
  assertEquals(replyTo, address.getRoutingKey());
}

代码示例来源:origin: spring-projects/spring-amqp

@Test
public void parseWithDefaultExchangeAndRoutingKey() {
  Address address = new Address("direct:///routing-key");
  assertEquals("", address.getExchangeName());
  assertEquals("routing-key", address.getRoutingKey());
  assertEquals("/routing-key", address.toString());
}

代码示例来源:origin: spring-projects/spring-amqp

@Override
public <R, S> boolean receiveAndReply(final String queueName, ReceiveAndReplyCallback<R, S> callback, final String replyExchange,
    final String replyRoutingKey) throws AmqpException {
  return receiveAndReply(queueName, callback,
      (request, reply) -> new Address(replyExchange, replyRoutingKey));
}

代码示例来源:origin: org.springframework.amqp/spring-rabbit

/**
 * Invoked by the container during startup so it can verify the queue is correctly
 * configured (if a simple reply queue name is used instead of exchange/routingKey).
 * @return the queue name, if configured.
 * @since 1.5
 */
@Override
@Nullable
public Collection<String> expectedQueueNames() {
  this.isListener = true;
  Collection<String> replyQueue = null;
  if (this.replyAddress == null || this.replyAddress.equals(Address.AMQ_RABBITMQ_REPLY_TO)) {
    throw new IllegalStateException("A listener container must not be provided when using direct reply-to");
  }
  else {
    Address address = new Address(this.replyAddress);
    if ("".equals(address.getExchangeName())) {
      replyQueue = Collections.singletonList(address.getRoutingKey());
    }
    else {
      if (logger.isInfoEnabled()) {
        logger.info("Cannot verify reply queue because 'replyAddress' is not a simple queue name: "
            + this.replyAddress);
      }
    }
  }
  return replyQueue;
}

相关文章