{"id":282831,"date":"2016-12-21T16:20:03","date_gmt":"2016-12-21T13:20:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=282831"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=282831","title":{"rendered":"\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f RabbitMQ Delayed Message Exchange \u0432 Java Spring Framework"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/58c\/aea\/d97\/58caead97ef0ce33afec4120ed5b8dff.png\" alt=\"image\" align=\"right\"\/> \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 RabbitMQ. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0437\u0430\u0434\u0430\u0447\u0438, \u0433\u0434\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u043e\u0437\u044c\u043c\u0443 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u043e\u0441\u0442\u0431\u0435\u043a\u043e\u0432 (<i>s2s ping back<\/i>, <i>s2s pixel<\/i>).<\/p>\n<h4>\u0412 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445 \u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435 \u043f\u043e\u0441\u0442\u0431\u0435\u043a\u043e\u0432:<\/h4>\n<p>  1. \u041f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0435\u043a\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435<br \/>  2. \u0412\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441<br \/>  3. \u0415\u0441\u043b\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0435\u0449\u0435 \u0440\u0430\u0437 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0443\u0442<\/p>\n<p>  \u0414\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c.<br \/>  <a name=\"habracut\"><\/a><br \/>  RabbitMQ \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u0435 \u0443\u043c\u0435\u0435\u0442 \u0437\u0430\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u043e\u043d\u0438 \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438. \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 \u0432\u0438\u0434\u0435 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 <a href=\"https:\/\/github.com\/rabbitmq\/rabbitmq-delayed-message-exchange\">rabbitmq-delayed-message-exchange<\/a>.<\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u0445\u043e\u0447\u0443 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u043b\u0430\u0433\u0438\u043d <b>\u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0439<\/b>. \u041d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0432 \u0446\u0435\u043b\u043e\u043c \u043e\u043d \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0442\u0430\u0431\u0438\u043b\u0435\u043d, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043d\u0430 \u0441\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u0445 \u0438 \u0440\u0438\u0441\u043a.<\/p>\n<h3>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c Docker \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441 RMQ \u0438 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u043c<\/h3>\n<p>  \u0417\u0430 \u043e\u0441\u043d\u043e\u0432\u0443 \u044f \u0432\u043e\u0437\u044c\u043c\u0443 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0437 \u0441 <a href=\"https:\/\/www.rabbitmq.com\/management.html\">management plugin<\/a>, \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  Dockerfile:<\/p>\n<pre><code>FROM rabbitmq:3.6-management RUN apt-get update && apt-get install -y curl RUN curl http:\/\/www.rabbitmq.com\/community-plugins\/v3.6.x\/rabbitmq_delayed_message_exchange-0.0.1.ez &gt; $RABBITMQ_HOME\/plugins\/rabbitmq_delayed_message_exchange-0.0.1.ez RUN rabbitmq-plugins enable --offline rabbitmq_delayed_message_exchange <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u0431\u043e\u0440\u043a\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">docker build --tag=x25\/rmq-delayed-message-exchange .<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0417\u0430\u043f\u0443\u0441\u043a<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"bash\">docker run -d --name rmq -p 5672:5672 -p 15672:15672 x25\/rmq-delayed-message-exchange<\/code><\/pre>\n<\/div>\n<\/div>\n<h3>Spring AMQP<\/h3>\n<p>  <b>Spring Framework<\/b> \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u043b\u0430\u0433\u0438\u043d \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 s<code>pring-rabbit<\/code>. \u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 1.6.4 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a xml\/bean \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u0442\u0430\u043a \u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438.<\/p>\n<p>  \u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Spring Boot Amqp Starter.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043b\u044f Maven<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"xml\">&lt;dependency&gt;     &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;     &lt;artifactId&gt;spring-boot-starter-amqp&lt;\/artifactId&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043b\u044f Gradle<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>compile &quot;org.springframework.boot:spring-boot-starter-amqp&quot;<\/code><\/pre>\n<\/div>\n<\/div>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438<\/h3>\n<p>  \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0443\u0442\u0441\u0442\u0440\u0430\u043f\u043f\u0435\u0440\u0430 \u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 Spring \u0431\u0435\u0440\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430 \u0441\u0435\u0431\u044f. \u0414\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438\u0448\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"java\">@RabbitListener(bindings = @QueueBinding(value = @Queue(value = DELAY_QUEUE_NAME), exchange = @Exchange(value = DELAY_EXCHANGE_NAME, delayed = &quot;true&quot;), key = DELAY_QUEUE_NAME)) public void onMessage(Message&lt;?&gt; message) {     \/\/... }<\/code><\/pre>\n<p>  \u0418 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f RabbitAdmin \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u0431\u044a\u044f\u0432\u0438\u0442 <code>delayed exchange<\/code>, <code>queue<\/code>, \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438 \u043f\u0440\u0438\u0432\u044f\u0436\u0435\u0442 \u0438\u0445 \u043a \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u0443.<\/p>\n<p>  \u041d\u0443\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439? \u042d\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0444\u0430\u0439\u043b \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 (\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <b>spring.rabbitmq.listener.concurrency<\/b>) \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <b>containerFactory<\/b> \u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438:<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">\/\/\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e: @Configuration public class RabbitConfiguration {     @Bean(name = &quot;containerFactory&quot;)     @Autowired     public SimpleRabbitListenerContainerFactory containerFactory(ConnectionFactory connectionFactory) {         SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();         factory.setConnectionFactory(connectionFactory);         factory.setConcurrentConsumers(10);         factory.setPrefetchCount(30);         return factory;     } }  \/\/\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440: @RabbitListener(containerFactory = &quot;containerFactory&quot;, ...)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u0414\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c RabbitTemplate:<\/p>\n<pre><code class=\"java\">rabbitTemplate.send(         DELAY_EXCHANGE_NAME,         DELAY_QUEUE_NAME,         MessageBuilder                 .withBody(data)                 .setHeader(&quot;x-delay&quot;, MESSAGE_DELAY_MS).build() );<\/code><\/pre>\n<p>  \u041e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e \u043e\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043c\u043e\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u043e, \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 <code>x-delay<\/code>. \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 (2^32-1) \u043c\u0441.<\/p>\n<p>  \u0413\u043e\u0442\u043e\u0432\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"java\">@SpringBootApplication public class Application {      private final Logger log = LoggerFactory.getLogger(Application.class);      private final static String DELAY_QUEUE_NAME = &quot;delayed.queue&quot;;     private final static String DELAY_EXCHANGE_NAME = &quot;delayed.exchange&quot;;      private final static String DELAY_HEADER = &quot;x-delay&quot;;     private final static String NUM_ATTEMPT_HEADER = &quot;x-num-attempt&quot;;     private final static long   RETRY_BACKOFF = 5000;      @Autowired     private RabbitTemplate rabbitTemplate;      @RabbitListener(bindings = @QueueBinding(value = @Queue(value = DELAY_QUEUE_NAME),     exchange = @Exchange(value = DELAY_EXCHANGE_NAME, delayed = &quot;true&quot;), key = DELAY_QUEUE_NAME))     public void onMessage(Message&lt;byte[]&gt; message) {          String endpointUrl = new String(message.getPayload());         Long numAttempt = (Long) message.getHeaders().getOrDefault(NUM_ATTEMPT_HEADER, 1L);          log.info(&quot;Message received, url={}, attempt={}&quot;, endpointUrl, numAttempt);          if (!doNotifyEndpoint(endpointUrl) && numAttempt &lt; 3) {             rabbitTemplate.send(                     DELAY_EXCHANGE_NAME,                     DELAY_QUEUE_NAME,                     MessageBuilder                             .withBody(message.getPayload())                             .setHeader(DELAY_HEADER, numAttempt * RETRY_BACKOFF)                             .setHeader(NUM_ATTEMPT_HEADER, numAttempt + 1)                             .build()             );         }     }      private boolean doNotifyEndpoint(String url) {         try {             HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();             \/* @todo: set up connection timeouts *\/             return (connection.getResponseCode() == 200);         } catch (Exception e) {             log.error(e.getMessage());             return false;         }     }      public static void main(String[] args) {         SpringApplication.run(Application.class, args);     } }<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">application.yml<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>spring:   rabbitmq:     host: 127.0.0.1     port: 5672     username: guest     password: guest     virtual-host: \/     listener:       prefetch: 10       concurrency: 50<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">build.gradle<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code>buildscript {     repositories {         mavenCentral()     }     dependencies {         classpath(&quot;org.springframework.boot:spring-boot-gradle-plugin:1.4.2.RELEASE&quot;)     } }  apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'org.springframework.boot'  jar {     baseName = 'rmq-delayed-demo'     version =  '0.1.0' }  repositories {     mavenCentral() }  sourceCompatibility = 1.8 targetCompatibility = 1.8  dependencies {     compile(&quot;org.springframework.boot:spring-boot-starter-amqp&quot;)     testCompile(&quot;org.springframework.boot:spring-boot-starter-test&quot;) }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f (rmq-management), \u043e\u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043d\u0430 \u043f\u043e\u0440\u0442\u0443 <b>15672<\/b>:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/i.gyazo.com\/74a810210df2662a9e2968c2db9febe0.png\" alt=\"image\"\/><\/p>\n<p>  \u041b\u043e\u0433\u0438:<\/p>\n<pre><code>2016-12-21 14:27:25.927: Message received, url=http:\/\/localhost:1234, attempt=1 2016-12-21 14:27:25.941: Connection refused (Connection refused) 2016-12-21 14:27:30.946: Message received, url=http:\/\/localhost:1234, attempt=2 2016-12-21 14:27:30.951: Connection refused (Connection refused) 2016-12-21 14:27:40.954: Message received, url=http:\/\/localhost:1234, attempt=3<\/code><\/pre>\n<h3>\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 XML<\/h3>\n<p>  \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 XML \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0443 exchange-\u0431\u0438\u043d\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>delayed<\/code> \u0432 <code>true<\/code> \u0438 RabbitAdmin \u0441\u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u0430 \u0432\u0430\u0441.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 xml-\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 Integration Framework<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;beans xmlns=&quot;http:\/\/www.springframework.org\/schema\/beans&quot;        xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xmlns:int=&quot;http:\/\/www.springframework.org\/schema\/integration&quot;        xmlns:int-amqp=&quot;http:\/\/www.springframework.org\/schema\/integration\/amqp&quot;        xmlns:rabbit=&quot;http:\/\/www.springframework.org\/schema\/rabbit&quot;        xsi:schemaLocation=&quot;http:\/\/www.springframework.org\/schema\/integration\/amqp http:\/\/www.springframework.org\/schema\/integration\/amqp\/spring-integration-amqp.xsd   http:\/\/www.springframework.org\/schema\/integration http:\/\/www.springframework.org\/schema\/integration\/spring-integration.xsd   http:\/\/www.springframework.org\/schema\/rabbit http:\/\/www.springframework.org\/schema\/rabbit\/spring-rabbit.xsd   http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd&quot;&gt;      &lt;int:channel id=&quot;to-delayed-rmq&quot; \/&gt;      &lt;int-amqp:outbound-channel-adapter channel=&quot;to-delayed-rmq&quot;                                        amqp-template=&quot;rabbitTemplate&quot;                                        exchange-name=&quot;delayed.exchange&quot;                                        routing-key=&quot;delayed.binding&quot;                                        mapped-request-headers=&quot;x-delay&quot; \/&gt;      &lt;int-amqp:inbound-channel-adapter channel=&quot;from-delayed-rmq-queue&quot;                                       queue-names=&quot;delayed.queue&quot;                                       message-converter=&quot;amqpMessageConverter&quot;                                       connection-factory=&quot;rabbitConnectionFactory&quot;                                       concurrent-consumers=&quot;10&quot;                                       prefetch-count=&quot;50&quot; \/&gt;      &lt;int:service-activator input-channel=&quot;from-delayed-rmq-queue&quot; method=&quot;onMessage&quot;&gt;         &lt;bean id=&quot;postbackServiceActivator&quot; class=&quot;PostbackServiceActivator&quot; \/&gt;     &lt;\/int:service-activator&gt;      &lt;rabbit:queue name=&quot;delayed.queue&quot; \/&gt;      &lt;rabbit:direct-exchange name=&quot;delayed.exchange&quot; delayed=&quot;true&quot;&gt;         &lt;rabbit:bindings&gt;             &lt;rabbit:binding queue=&quot;delayed.queue&quot; key=&quot;delayed.binding&quot; \/&gt;         &lt;\/rabbit:bindings&gt;     &lt;\/rabbit:direct-exchange&gt;  &lt;\/beans&gt;<\/code><\/pre>\n<\/div>\n<\/div>\n<h3>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h3>\n<p>  <\/p>\n<ul>\n<li><a href=\"http:\/\/docs.spring.io\/spring-amqp\/reference\/html\/_reference.html#delayed-message-exchange\">\u041e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/rabbitmq\/rabbitmq-delayed-message-exchange\">\u0421\u0442\u0440\u0430\u043d\u0438\u0446\u0430 \u043f\u043b\u0430\u0433\u0438\u043d\u0430<\/a><\/li>\n<\/ul>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/318118\/\"> https:\/\/habrahabr.ru\/post\/318118\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/58c\/aea\/d97\/58caead97ef0ce33afec4120ed5b8dff.png\" alt=\"image\" align=\"right\"\/> \u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 RabbitMQ. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0437\u0430\u0434\u0430\u0447\u0438, \u0433\u0434\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u043e\u0437\u044c\u043c\u0443 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u043e\u0441\u0442\u0431\u0435\u043a\u043e\u0432 (<i>s2s ping back<\/i>, <i>s2s pixel<\/i>).<\/p>\n<h4>\u0412 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445 \u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0435 \u043f\u043e\u0441\u0442\u0431\u0435\u043a\u043e\u0432:<\/h4>\n<p>  1. \u041f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0435\u043a\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435<br \/>  2. \u0412\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441<br \/>  3. \u0415\u0441\u043b\u0438 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0439 \u0441\u0435\u0440\u0432\u0438\u0441 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0435\u0449\u0435 \u0440\u0430\u0437 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0443\u0442<\/p>\n<p>  \u0414\u043b\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-282831","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/282831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=282831"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/282831\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=282831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=282831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=282831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}