{"id":308862,"date":"2020-08-22T09:00:18","date_gmt":"2020-08-22T09:00:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308862"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308862","title":{"rendered":"\u041e\u0447\u0435\u0440\u0435\u0434\u044c \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 delayedQueue"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/516178\/\">\n<p>\u041f\u0430\u0440\u0443 \u043b\u0435\u0442 \u043d\u0430\u0437\u0430\u0434 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043c\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0435\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0437\u043d\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u043f\u043b\u0430\u0442\u0435\u0436\u0430 \u0447\u0435\u0440\u0435\u0437 \u0442\u0440\u0438 \u0447\u0430\u0441\u0430 \u0438\u043b\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 45 \u043c\u0438\u043d\u0443\u0442. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u044b \u043d\u0435 \u043d\u0430\u0448\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0445 &quot;\u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c&quot; \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0445 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0438 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u044e. \u041c\u044b \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/fred84\/delayedQueue\" rel=\"nofollow\">delayed queue<\/a> \u043d\u0430 Java \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Redis \u0432 \u0440\u043e\u043b\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0435\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0438 \u0442\u0435 &quot;\u0433\u0440\u0430\u0431\u043b\u0438&quot;, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435. <\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2 id=\"funkcionalnost\">\u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0447\u0442\u043e \u0436\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 delayed queue? \u0421\u043e\u0431\u044b\u0442\u0438\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0432 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e, \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u0437\u0434\u043d\u0435\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e. Redis \u043d\u0435 \u0434\u0430\u0435\u0442 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0439 \u0441\u043e\u0445\u0440\u0430\u043d\u043d\u043e\u0441\u0442\u0438, \u0438 \u043a \u043f\u043e\u0442\u0435\u0440\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 <strong>\u043d\u0443\u0436\u043d\u043e<\/strong> \u0431\u044b\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u044b\u043c. \u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 Redis \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u044c, \u0438 \u043c\u044b \u043d\u0438 \u0440\u0430\u0437\u0443 \u043d\u0435 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u044d\u0442\u0438\u043c \u0437\u0430 \u043f\u043e\u043b\u0442\u043e\u0440\u0430 \u0433\u043e\u0434\u0430 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u0438. <\/p>\n<p>  <\/p>\n<h3 id=\"api\">API<\/h3>\n<p>  <\/p>\n<h4 id=\"dobavit-sobytie-v-ochered\">\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c<\/h4>\n<p>  <\/p>\n<pre><code class=\"java\">eventService.enqueueWithDelayNonBlocking(new DummyEvent(&quot;1&quot;), Duration.ofHours(1)).subscribe();<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>Mono<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0430\u0434\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043e\u0434\u043d\u043e \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>subscribe(...)<\/code><\/li>\n<li><code>block()<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0435 \u0440\u0430\u0437\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e <code>Project Reactor<\/code>. \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a \u0441\u043e\u0431\u044b\u0442\u0438\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">eventService.enqueueWithDelayNonBlocking(new DummyEvent(&quot;1&quot;), Duration.ofHours(1), Map.of(&quot;key&quot;, &quot;value&quot;)).subscribe();<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"zaregistrirovat-obrabotchik-sobytiy\">\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/h4>\n<p>  <\/p>\n<pre><code class=\"java\">eventService.addHandler(DummyEvent.class, e -&gt; Mono.just(true), 1);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0435\u0441\u043b\u0438 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0441\u043e\u0431\u044b\u0442\u0438\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u0438\u0448\u0435\u0434\u0448\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">eventService.addHandler(         DummyEvent.class,         e -&gt; Mono             .subscriberContext()             .doOnNext(ctx -&gt; {                 Map&lt;String, String&gt; eventContext = ctx.get(&quot;eventContext&quot;);                 log.info(&quot;context key {}&quot;, eventContext.get(&quot;key&quot;));             })             .thenReturn(true),         1 );<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"udalit-obrabotchik-sobytiy\">\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/h4>\n<p>  <\/p>\n<pre><code class=\"java\">eventService.removeHandler(DummyEvent.class);<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"sozdanie-servisa\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/h4>\n<p>  <\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 &quot;\u043f\u043e-\u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e&quot;:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import static com.github.fred84.queue.DelayedEventService.delayedEventService;  var eventService = delayedEventService().client(redisClient).build();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438\u043b\u0438 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0451 \u0441\u0430\u043c\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">import static com.github.fred84.queue.DelayedEventService.delayedEventService;  var eventService = delayedEventService()         .client(redisClient)         .mapper(objectMapper)         .handlerScheduler(Schedulers.fromExecutorService(executor))         .schedulingInterval(Duration.ofSeconds(1))         .schedulingBatchSize(SCHEDULING_BATCH_SIZE)         .enableScheduling(false)         .pollingTimeout(POLLING_TIMEOUT)         .eventContextHandler(new DefaultEventContextHandler())         .dataSetPrefix(&quot;&quot;)         .retryAttempts(10)         .metrics(new NoopMetrics())         .refreshSubscriptionsInterval(Duration.ofMinutes(5))         .build();<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 (\u0438 \u0432\u0441\u0435\u0445 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0438\u043c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0432 Redis) \u043c\u043e\u0436\u043d\u043e <code>eventService.close()<\/code> \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e <code>@javax.annotation.PreDestroy<\/code>.<\/p>\n<p>  <\/p>\n<h4 id=\"metriki\">\u041c\u0435\u0442\u0440\u0438\u043a\u0438<\/h4>\n<p>  <\/p>\n<p>\u0421 \u043b\u044e\u0431\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u0447\u0442\u043e-\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u043d\u0435 \u0442\u0430\u043a, \u0437\u0430 \u043d\u0435\u0439 \u043d\u0430\u0434\u043e \u043f\u0440\u0438\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0442\u044c. \u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0432\u0430\u0441 \u0434\u043e\u043b\u0436\u043d\u044b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0442\u044c:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043e\u0431\u0449\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043f\u0430\u043c\u044f\u0442\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 Redis;<\/li>\n<li>\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 (\u043c\u0435\u0442\u0440\u0438\u043a\u0430 &quot;delayed.queue.ready.for.handling.count&quot; \u0438 \u0442\u044d\u0433\u043e\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f)<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"istoriya\">\u0418\u0441\u0442\u043e\u0440\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0438 \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u043b\u0441\u044f delayed queue. \u0412 2018 \u0433\u043e\u0434\u0443<br \/>  \u043d\u0430\u0448 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 \u0431\u044b\u043b \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u0432 <a href=\"https:\/\/aws.amazon.com\/\" rel=\"nofollow\">Amazon Web Services<\/a>.<br \/>  \u041e\u043d \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0441\u044f \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u043b\u0441\u044f \u0434\u0432\u0443\u043c\u044f \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430\u043c\u0438, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0435 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0431\u044b\u043b\u043e \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u043e \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u043e\u043c \u0431\u044b\u043b\u043e: &quot;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0435 Amazon-\u043e\u043c, \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0447\u0435\u043d\u044c \u0434\u043e\u0440\u043e\u0433\u043e&quot;.<\/p>\n<p>  <\/p>\n<h3 id=\"gotovye-kandidaty\">\u0413\u043e\u0442\u043e\u0432\u044b\u0435 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u044b<\/h3>\n<p>  <\/p>\n<p>\u041c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438: <\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/www.rabbitmq.com\" rel=\"nofollow\">RabbitMQ<\/a><\/li>\n<li>JMS<\/li>\n<li><a href=\"https:\/\/aws.amazon.com\/sqs\/\" rel=\"nofollow\">AWS SQS<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u0431\u044b\u043b\u0438 \u043e\u0442\u0441\u0435\u044f\u043d\u044b \u0438\u0437-\u0437\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0445 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0438 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0442\u044c, \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0441 JMS \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0432\u0430\u043b\u043e \u043e\u043f\u044b\u0442\u0430 \u0440\u0430\u0431\u043e\u0442\u044b. SQS \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u043b\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 15 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<p>  <\/p>\n<h3 id=\"pervaya-naivnaya-realizaciya\">\u041f\u0435\u0440\u0432\u0430\u044f \u043d\u0430\u0438\u0432\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u041d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u0442\u0430\u0440\u0442\u0430 \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0431\u044b\u043b \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u043e\u0431\u0445\u043e\u0434\u043e\u043c &quot;\u0437\u0430\u0432\u0438\u0441\u0448\u0438\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439&quot; \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0411\u0414 \u0440\u0430\u0437 \u0432 \u0441\u0443\u0442\u043a\u0438. \u041f\u043e\u0447\u0438\u0442\u0430\u0432 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u0440\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u043c\u044b \u0432\u044b\u0431\u0440\u0430\u043b\u0438 Redis \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 <a href=\"https:\/\/redis.io\/topics\/data-types\" rel=\"nofollow\">sorted sets<\/a>, \u0433\u0434\u0435 \u0432\u0435\u0441\u043e\u043c \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0435\u0435 \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f<\/li>\n<li>\u043f\u043e \u043d\u0430\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u044e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438\u0437 &quot;sorted_set&quot; \u0432 &quot;list&quot; (\u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u0438)<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0417\u0430\u0431\u0435\u0433\u0430\u044f \u0432\u043f\u0435\u0440\u0435\u0434, \u043d\u0430 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0443\u0436\u0435 \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b \u043f\u0440\u043e\u0435\u043a\u0442 <a href=\"https:\/\/github.com\/Netflix\/dyno-queues\" rel=\"nofollow\">Netflix dyno-queues<\/a><br \/>  \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u044b. \u041e\u0434\u043d\u0430\u043a\u043e \u0442\u043e\u0433\u0434\u0430 \u044f \u0435\u0433\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0435\u0449\u0435 \u043d\u0435 \u043d\u0430\u0448\u0435\u043b.<\/p>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b &quot;\u0441\u043e\u0437\u0440\u0435\u0432\u0448\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f&quot; \u0438\u0437 sorted set \u0432 list, \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a (\u0437\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434):<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">var events = redis.zrangebyscore(&quot;delayed_events&quot;, Range.create(-1, System.currentTimeMillis()), 100); events.forEach(key -&gt; {   var payload = extractPayload(key);   var listName = extractType(key);   redis.lpush(listName, payload);   redis.zrem(&quot;delayed_events&quot;, key); });<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0431\u044b\u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u043d\u044b \u043f\u043e\u0432\u0435\u0440\u0445 <a href=\"https:\/\/spring.io\/projects\/spring-integration\" rel=\"nofollow\">Spring Integration<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u0435\u043b\u0430\u043b:<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">redis.brpop(listName)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0435 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0441\u0435\u0431\u044f \u0434\u043e\u043b\u0433\u043e \u0436\u0434\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<h3 id=\"nenadezhnyy-dispetcher\">\u041d\u0435\u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440<\/h3>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0432 &quot;list&quot; (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u0432\u0430\u043b\u0438\u043b\u043e\u0441\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435), \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043f\u043e\u043c\u0435\u0449\u0430\u043b\u043e\u0441\u044c \u0432 list \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 Redis \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u043b\u0438 \u044d\u0442\u0438 2 \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">events.forEach(key -&gt; {   ...   redis.multi();   redis.zrem(&quot;delayed_events&quot;, key);   redis.lpush(listName, payload);   redis.exec(); });<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"nenadezhnyy-obrabotchik\">\u041d\u0435\u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a<\/h3>\n<p>  <\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b list-a \u043d\u0430\u0441 \u043f\u043e\u0434\u0436\u0438\u0434\u0430\u043b\u0430 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u043f\u0440\u043e\u043f\u0430\u0434\u0430\u043b\u043e \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430, \u0435\u0441\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430. \u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0441\u0442\u0430\u043b\u0430 \u0437\u0430\u043c\u0435\u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0438\u0437 &quot;sorted_set&quot; \u043d\u0430 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044c \u0435\u0433\u043e \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0437\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">events.forEach(key -&gt; {   ...   redis.multi();   redis.zadd(&quot;delayed_events&quot;, nextAttempt(key))   redis.zrem(&quot;delayed_events&quot;, key);   redis.lpush(listName, payload);   redis.exec(); });<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"ne-unikalnoe-sobytie\">\u041d\u0435 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435<\/h3>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b, \u0443 \u043d\u0430\u0441 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b \u0437\u0430\u043f\u0430\u0441\u043d\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0445\u043e\u0434\u0438\u043b &quot;\u0437\u0430\u0432\u0438\u0441\u0448\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438&quot; \u0432 \u0411\u0414 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b \u0432 &quot;delayed queue&quot; \u0435\u0449\u0435 \u043e\u0434\u043d\u043e. \u0412\u043d\u0443\u0442\u0440\u0438 &quot;sorted set&quot; \u043a\u043b\u044e\u0447 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u043a\u0430\u043a<br \/>  <code>metadata;payload<\/code>, \u0433\u0434\u0435 payload \u0443 \u043d\u0430\u0441 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u043d\u044b\u0439, \u0430 \u0432\u043e\u0442 metadata \u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e-\u0436\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043e\u0442\u043b\u0438\u0447\u0430\u043b\u0430\u0441\u044c. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442 \u0438 \u043c\u043d\u043e\u0433\u043e \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u042d\u0442\u0443 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438, \u0432\u044b\u043d\u0435\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u0443\u044e metadata \u0438 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u043d\u044b\u0439 payload \u0432 <code>Redis hset<\/code> \u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u0432 &quot;sorted set&quot; \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u043e\u0431\u044b\u0442\u0438\u044f.<br \/>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043b\u0430\u0441\u044c \u0438\u0437 <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">var envelope = metadata + SEPARATOR + payload; redis.zadd(envelope, scheduledAt);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0432 <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">var envelope = metadata + SEPARATOR + payload; var key = eventType + SEPARATOR + eventId;  redis.multi(); redis.zadd(key, scheduledAt); redis.hset(&quot;metadata&quot;, key, envelope) redis.exec();<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"posledovatelnyy-zapusk-dispetchera\">\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430<\/h3>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u043d\u0430\u0448\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0431\u044b\u043b\u0438 \u0438\u0434\u0435\u043c\u043f\u043e\u0442\u0435\u043d\u0442\u043d\u044b\u043c\u0438, \u0438 \u043c\u044b \u043d\u0435 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u043b\u0438\u0441\u044c \u043e \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u0430\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u0438\u0441\u043f\u0435\u0447\u0435\u0440\u044b \u0438\u043d\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0438\u0441\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438 \u0432 list \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0441 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u043c TTL \u0441\u0434\u0435\u043b\u0430\u043b\u043e \u043a\u043e\u0434 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c: <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">redis.set(lockKey, &quot;value&quot;, ex(lockTimeout.toMillis() * 1000).nx());<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"evolyuciya-v-otdelnyy-proekt\">\u042d\u0432\u043e\u043b\u044e\u0446\u0438\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442<\/h2>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0442\u0430\u043a\u0443\u044e \u0436\u0435 \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u043b\u043e\u0441\u044c \u0440\u0435\u0448\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0431\u0435\u0437 Spring, \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0431\u044b\u043b \u0432\u044b\u043d\u0435\u0441\u0435\u043d \u0432 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. &quot;\u041f\u043e\u0434 \u043d\u043e\u0436&quot; \u043f\u043e\u0448\u043b\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/spring.io\/projects\/spring-data-redis\" rel=\"nofollow\">Spring Data Redis<\/a><\/li>\n<li><a href=\"https:\/\/spring.io\/projects\/spring-integration\" rel=\"nofollow\">Spring integration<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u0431\u044b\u043b\u0430 \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043c\u0435\u043d\u0435\u043d\u0430 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Lettuce \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0430 \u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0441\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0447\u0443\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u041a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u0443 \u043c\u0435\u043d\u044f \u0431\u044b\u043b \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438 \u0441\u0442\u0440\u0438\u043c\u0430\u043c\u0438 \u0432 \u043e\u0431\u0449\u0435\u043c \u0438 \u0441 Project Reactor \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0441\u0442\u0430\u043b &quot;\u0433\u043e\u0440\u044f\u0447\u0438\u0439 \u0441\u0442\u0440\u0438\u043c&quot;.<br \/>  \u0427\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 <a href=\"https:\/\/www.reactive-streams.org\/reactive-streams-1.0.0-javadoc\/org\/reactivestreams\/Subscriber.html\" rel=\"nofollow\">Subscriber<\/a> <\/p>\n<p>  <\/p>\n<pre><code class=\"java\">redis   .reactive()   .brpop(timeout, queue)   .map(e -&gt; deserialize(e))   .subscribe(new InnerSubscriber&lt;&gt;(handler, ... params ..))<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438<\/p>\n<p>  <\/p>\n<pre><code class=\"java\">class InnerSubscriber&lt;T extends Event&gt; extends BaseSubscriber&lt;EventEnvelope&lt;T&gt;&gt; {      @Override     protected void hookOnNext(@NotNull EventEnvelope&lt;T&gt; envelope) {         Mono&lt;Boolean&gt; promise = handler.apply(envelope.getPayload());         promise.subscribe(r -&gt; request(1));     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0430\u043c\u0430 \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 (\u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 Netflix dyno queue, \u0433\u0434\u0430 \u043d\u0430\u0434\u043e \u0441\u0430\u043c\u043e\u043c\u0443 poll-\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f).<\/p>\n<p>  <\/p>\n<h3 id=\"chto-planiruem-dalshe\">\u0427\u0442\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435?<\/h3>\n<p>  <\/p>\n<ul>\n<li>\u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c Kotlin DSL. \u041d\u043e\u0432\u044b\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u044f \u0432\u0441\u0435 \u0447\u0430\u0449\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e \u043d\u0430 Kotlin \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>suspend fun<\/code> \u0432\u043c\u0435\u0441\u0442\u043e API <code>Project Reactor<\/code> \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u0435\u0435<\/li>\n<li>\u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u044b \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u043c\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0430\u043c\u0438<\/li>\n<\/ul>\n<p>  <\/p>\n<h2 id=\"ccylki\">Cc\u044b\u043b\u043a\u0438<\/h2>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/fred84\/delayedQueue\" rel=\"nofollow\">delayed queue<\/a><\/li>\n<li><a href=\"https:\/\/redis.io\/topics\/data-types\" rel=\"nofollow\">Redis sorted sets<\/a><\/li>\n<li><a href=\"https:\/\/projectreactor.io\" rel=\"nofollow\">Project reactor<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/FasterXML\/jackson\" rel=\"nofollow\">Jackson<\/a><\/li>\n<li><a href=\"https:\/\/micrometer.io\" rel=\"nofollow\">Micrometer<\/a><\/li>\n<li><a href=\"https:\/\/lettuce.io\" rel=\"nofollow\">Lettuce<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/Netflix\/dyno-queues\" rel=\"nofollow\">Netflix dyno-queues<\/a><\/li>\n<\/ul>\n<\/div>\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:\/\/habr.com\/ru\/post\/516178\/\"> https:\/\/habr.com\/ru\/post\/516178\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/516178\/\">\n<p>\u041f\u0430\u0440\u0443 \u043b\u0435\u0442 \u043d\u0430\u0437\u0430\u0434 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432 \u043c\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043d\u0435\u043a\u043e\u0435\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u0437\u043d\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u043f\u043b\u0430\u0442\u0435\u0436\u0430 \u0447\u0435\u0440\u0435\u0437 \u0442\u0440\u0438 \u0447\u0430\u0441\u0430 \u0438\u043b\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0447\u0435\u0440\u0435\u0437 45 \u043c\u0438\u043d\u0443\u0442. \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u044b \u043d\u0435 \u043d\u0430\u0448\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b\u0445 &quot;\u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c&quot; \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0445 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0438 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u044e. \u041c\u044b \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/fred84\/delayedQueue\" rel=\"nofollow\">delayed queue<\/a> \u043d\u0430 Java \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Redis \u0432 \u0440\u043e\u043b\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u0435\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0438 \u0442\u0435 &quot;\u0433\u0440\u0430\u0431\u043b\u0438&quot;, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435. <\/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-308862","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308862","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=308862"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308862\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}