|
| 1 | +--- |
| 2 | +sidebar_position: 1 |
| 3 | +--- |
| 4 | + |
| 5 | +# Single Broker |
| 6 | + |
| 7 | +import Tabs from '@theme/Tabs'; |
| 8 | +import TabItem from '@theme/TabItem'; |
| 9 | +import ThemeImage from '../../src/components/ThemeImage'; |
| 10 | + |
| 11 | +<ThemeImage scenario="1"></ThemeImage> |
| 12 | + |
| 13 | +Both apps the `App 1` and the `App 2` are connected to the same `Broker`, so both has the same connection configuration, |
| 14 | +and `Broker` is considered the `app` domain for both apps. |
| 15 | + |
| 16 | +<Tabs> |
| 17 | + <TabItem value="rabbitmq" label="RabbitMQ" default> |
| 18 | + |
| 19 | +You can customize some predefined variables of Reactive Commons |
| 20 | + |
| 21 | +This can be done by Spring Boot `application.yaml` or by overriding |
| 22 | +the [AsyncProps](https://github.com/reactive-commons/reactive-commons-java/blob/master/starters/async-rabbit-starter/src/main/java/org/reactivecommons/async/rabbit/config/props/AsyncProps.java) |
| 23 | +bean. |
| 24 | + |
| 25 | +```yaml |
| 26 | +app: |
| 27 | + async: |
| 28 | + app: # this is the name of the default domain |
| 29 | + withDLQRetry: false # if you want to have dlq queues with retries you can set it to true, you cannot change it after queues are created, because you will get an error, so you should delete topology before the change. |
| 30 | + maxRetries: -1 # -1 will be considered default value. When withDLQRetry is true, it will be retried 10 times. When withDLQRetry is false, it will be retried indefinitely. |
| 31 | + retryDelay: 1000 # interval for message retries, with and without DLQRetry |
| 32 | + listenReplies: true # if you will not use ReqReply patter you can set it to false |
| 33 | + createTopology: true # if your organization have restrictions with automatic topology creation you can set it to false and create it manually or by your organization process. |
| 34 | + delayedCommands: false # Enable to send a delayed command to an external target |
| 35 | + prefetchCount: 250 # is the maximum number of in flight messages you can reduce it to process less concurrent messages, this settings acts per instance of your service |
| 36 | + useDiscardNotifierPerDomain: false # if true it uses a discard notifier for each domain,when false it uses a single discard notifier for all domains with default 'app' domain |
| 37 | + enabled: true # if you want to disable this domain you can set it to false |
| 38 | + brokerType: "rabbitmq" # please don't change this value |
| 39 | + flux: |
| 40 | + maxConcurrency: 250 # max concurrency of listener flow |
| 41 | + domain: |
| 42 | + ignoreThisListener: false # Allows you to disable event listener for this specific domain |
| 43 | + events: |
| 44 | + exchange: domainEvents # you can change the exchange, but you should do it in all applications consistently |
| 45 | + eventsSuffix: subsEvents # events queue name suffix, name will be like ${spring.application.name}.${app.async.domain.events.eventsSuffix} |
| 46 | + notificationSuffix: notification # notification events queue name suffix |
| 47 | + direct: |
| 48 | + exchange: directMessages # you can change the exchange, but you should do it in all applications |
| 49 | + querySuffix: query # queries queue name suffix, name will be like ${spring.application.name}.${app.async.direct.querySuffix} |
| 50 | + commandSuffix: '' # commands queue name suffix, name will be like ${spring.application.name}.${app.async.direct.querySuffix} or ${spring.application.name} if empty by default |
| 51 | + discardTimeoutQueries: false # enable to discard this condition |
| 52 | + global: |
| 53 | + exchange: globalReply # you can change the exchange, but you should do it in all applications |
| 54 | + repliesSuffix: replies # async query replies events queue name suffix |
| 55 | + connectionProperties: # you can override the connection properties of each domain |
| 56 | + host: localhost |
| 57 | + port: 5672 |
| 58 | + username: guest |
| 59 | + password: guest |
| 60 | + virtual-host: / |
| 61 | +``` |
| 62 | +
|
| 63 | +You can override this settings programmatically through a `AsyncPropsDomainProperties` bean. |
| 64 | + |
| 65 | +```java |
| 66 | +package sample; |
| 67 | +
|
| 68 | +import org.reactivecommons.async.rabbit.config.RabbitProperties; |
| 69 | +import org.reactivecommons.async.rabbit.config.props.AsyncProps; |
| 70 | +import org.reactivecommons.async.rabbit.config.props.AsyncRabbitPropsDomainProperties; |
| 71 | +import org.springframework.context.annotation.Bean; |
| 72 | +import org.springframework.context.annotation.Primary; |
| 73 | +
|
| 74 | +@Configuration |
| 75 | +public class MyDomainConfig { |
| 76 | +
|
| 77 | + @Bean |
| 78 | + @Primary |
| 79 | + public AsyncPropsDomainProperties customDomainProperties() { |
| 80 | + RabbitProperties propertiesApp = new RabbitProperties(); |
| 81 | + propertiesApp.setHost("localhost"); |
| 82 | + propertiesApp.setPort(5672); |
| 83 | + propertiesApp.setVirtualHost("/"); |
| 84 | + propertiesApp.setUsername("guest"); |
| 85 | + propertiesApp.setPassword("guest"); |
| 86 | +
|
| 87 | + return AsyncPropsDomainProperties.builder() |
| 88 | + .withDomain("app", AsyncProps.builder() |
| 89 | + .connectionProperties(propertiesApp) |
| 90 | + .build()) |
| 91 | + .build(); |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +Additionally, if you want to set only connection properties you can use the `AsyncPropsDomain.SecretFiller` class. |
| 97 | + |
| 98 | +```java |
| 99 | +
|
| 100 | +@Bean |
| 101 | +@Primary |
| 102 | +public AsyncPropsDomain.SecretFiller customFiller() { |
| 103 | + return (domain, asyncProps) -> { |
| 104 | + // customize asyncProps here by domain |
| 105 | + }; |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | + </TabItem> |
| 110 | + <TabItem value="kafka" label="Kafka"> |
| 111 | + You can customize some predefined variables of Reactive Commons |
| 112 | + |
| 113 | +This can be done by Spring Boot `application.yaml` or by overriding |
| 114 | +the [AsyncKafkaProps](https://github.com/reactive-commons/reactive-commons-java/blob/master/starters/async-kafka-starter/src/main/java/org/reactivecommons/async/kafka/config/props/AsyncKafkaProps.java) |
| 115 | +bean. |
| 116 | + |
| 117 | +```yaml |
| 118 | +reactive: |
| 119 | + commons: |
| 120 | + kafka: |
| 121 | + app: # this is the name of the default domain |
| 122 | + withDLQRetry: false # if you want to have dlq queues with retries you can set it to true, you cannot change it after queues are created, because you will get an error, so you should delete topology before the change. |
| 123 | + maxRetries: -1 # -1 will be considered default value. When withDLQRetry is true, it will be retried 10 times. When withDLQRetry is false, it will be retried indefinitely. |
| 124 | + retryDelay: 1000 # interval for message retries, with and without DLQRetry |
| 125 | + checkExistingTopics: true # if you don't want to verify topic existence before send a record you can set it to false |
| 126 | + createTopology: true # if your organization have restrictions with automatic topology creation you can set it to false and create it manually or by your organization process. |
| 127 | + useDiscardNotifierPerDomain: false # if true it uses a discard notifier for each domain,when false it uses a single discard notifier for all domains with default 'app' domain |
| 128 | + enabled: true # if you want to disable this domain you can set it to false |
| 129 | + brokerType: "kafka" # please don't change this value |
| 130 | + domain: |
| 131 | + ignoreThisListener: false # Allows you to disable event listener for this specific domain |
| 132 | + connectionProperties: # you can override the connection properties of each domain |
| 133 | + bootstrap-servers: localhost:9092 |
| 134 | +``` |
| 135 | + |
| 136 | +You can override this settings programmatically through a `AsyncKafkaPropsDomainProperties` bean. |
| 137 | + |
| 138 | +```java |
| 139 | +package sample; |
| 140 | +
|
| 141 | +import org.reactivecommons.async.kafka.config.KafkaProperties; |
| 142 | +import org.reactivecommons.async.kafka.config.props.AsyncProps; |
| 143 | +import org.reactivecommons.async.kafka.config.props.AsyncKafkaPropsDomainProperties; |
| 144 | +import org.springframework.context.annotation.Bean; |
| 145 | +import org.springframework.context.annotation.Primary; |
| 146 | +
|
| 147 | +@Configuration |
| 148 | +public class MyDomainConfig { |
| 149 | +
|
| 150 | + @Bean |
| 151 | + @Primary |
| 152 | + public AsyncKafkaPropsDomainProperties customKafkaDomainProperties() { |
| 153 | + KafkaProperties propertiesApp = new KafkaProperties(); |
| 154 | + propertiesApp.setBootstrapServers(List.of("localhost:9092")); |
| 155 | +
|
| 156 | + return AsyncKafkaPropsDomainProperties.builder() |
| 157 | + .withDomain("app", AsyncProps.builder() |
| 158 | + .connectionProperties(propertiesApp) |
| 159 | + .build()) |
| 160 | + .build(); |
| 161 | + } |
| 162 | +} |
| 163 | +``` |
| 164 | + |
| 165 | +Additionally, if you want to set only connection properties you can use the `AsyncKafkaPropsDomain.KafkaSecretFiller` |
| 166 | +class. |
| 167 | + |
| 168 | +```java |
| 169 | +
|
| 170 | +@Bean |
| 171 | +@Primary |
| 172 | +public AsyncKafkaPropsDomain.KafkaSecretFiller customKafkaFiller() { |
| 173 | + return (domain, asyncProps) -> { |
| 174 | + // customize asyncProps here by domain |
| 175 | + }; |
| 176 | +} |
| 177 | +``` |
| 178 | + |
| 179 | + </TabItem> |
| 180 | +</Tabs> |
0 commit comments