|
29 | 29 | import org.springframework.integration.amqp.inbound.AmqpClientInboundGateway; |
30 | 30 | import org.springframework.integration.amqp.support.AmqpHeaderMapper; |
31 | 31 | import org.springframework.integration.dsl.MessagingGatewaySpec; |
32 | | -import org.springframework.scheduling.TaskScheduler; |
33 | 32 |
|
34 | 33 | /** |
35 | 34 | * Spec for an {@link AmqpClientInboundGateway}. |
|
41 | 40 | public class AmqpClientInboundGatewaySpec |
42 | 41 | extends MessagingGatewaySpec<AmqpClientInboundGatewaySpec, AmqpClientInboundGateway> { |
43 | 42 |
|
| 43 | + /** |
| 44 | + * Create an instance based on a {@link AmqpConnectionFactory} and queues to consume from. |
| 45 | + * @param connectionFactory the {@link AmqpConnectionFactory} to connect |
| 46 | + * @param queueNames queues to consume from |
| 47 | + */ |
44 | 48 | public AmqpClientInboundGatewaySpec(AmqpConnectionFactory connectionFactory, String... queueNames) { |
45 | 49 | super(new AmqpClientInboundGateway(connectionFactory, queueNames)); |
46 | 50 | } |
47 | 51 |
|
| 52 | + /** |
| 53 | + * The initial number credits to grant to the AMQP receiver. |
| 54 | + * The default is {@code 100}. |
| 55 | + * @param initialCredits number of initial credits |
| 56 | + * @return the spec |
| 57 | + */ |
48 | 58 | public AmqpClientInboundGatewaySpec initialCredits(int initialCredits) { |
49 | 59 | this.target.setInitialCredits(initialCredits); |
50 | 60 | return this; |
51 | 61 | } |
52 | 62 |
|
| 63 | + /** |
| 64 | + * The consumer priority. |
| 65 | + * @param priority consumer priority |
| 66 | + * @return the spec |
| 67 | + */ |
53 | 68 | public AmqpClientInboundGatewaySpec priority(int priority) { |
54 | 69 | this.target.setPriority(priority); |
55 | 70 | return this; |
56 | 71 | } |
57 | 72 |
|
| 73 | + /** |
| 74 | + * Add {@link Resource.StateListener} instances to the consumer. |
| 75 | + * @param stateListeners listeners to add |
| 76 | + * @return the spec |
| 77 | + */ |
58 | 78 | public AmqpClientInboundGatewaySpec stateListeners(Resource.StateListener... stateListeners) { |
59 | 79 | this.target.setStateListeners(stateListeners); |
60 | 80 | return this; |
61 | 81 | } |
62 | 82 |
|
| 83 | + /** |
| 84 | + * Add {@link MessagePostProcessor} instances to apply on just received messages. |
| 85 | + * @param afterReceivePostProcessors listeners to add |
| 86 | + * @return the spec |
| 87 | + */ |
63 | 88 | public AmqpClientInboundGatewaySpec afterReceivePostProcessors( |
64 | 89 | MessagePostProcessor... afterReceivePostProcessors) { |
65 | 90 |
|
66 | 91 | this.target.setAfterReceivePostProcessors(afterReceivePostProcessors); |
67 | 92 | return this; |
68 | 93 | } |
69 | 94 |
|
70 | | - public AmqpClientInboundGatewaySpec taskScheduler(TaskScheduler taskScheduler) { |
71 | | - this.target.setTaskScheduler(taskScheduler); |
72 | | - return this; |
73 | | - } |
74 | | - |
| 95 | + /** |
| 96 | + * Set {@link Advice} instances to proxy message listener. |
| 97 | + * @param advices the taskScheduler to add |
| 98 | + * @return the spec |
| 99 | + */ |
75 | 100 | public AmqpClientInboundGatewaySpec adviceChain(Advice... advices) { |
76 | 101 | this.target.setAdviceChain(advices); |
77 | 102 | return this; |
78 | 103 | } |
79 | 104 |
|
| 105 | + /** |
| 106 | + * Set to {@code false} to propagate an acknowledgement callback into message headers |
| 107 | + * for downstream flow manual settlement. |
| 108 | + * @param autoSettle {@code true} to acknowledge messages automatically. |
| 109 | + * @return the spec |
| 110 | + */ |
80 | 111 | public AmqpClientInboundGatewaySpec autoSettle(boolean autoSettle) { |
81 | 112 | this.target.setAutoSettle(autoSettle); |
82 | 113 | return this; |
83 | 114 | } |
84 | 115 |
|
| 116 | + /** |
| 117 | + * Set the default behavior when a message processing has failed. |
| 118 | + * When true, messages will be requeued, when false, they will be discarded. |
| 119 | + * When true, the default can be overridden by the listener throwing an |
| 120 | + * {@link org.springframework.amqp.AmqpRejectAndDontRequeueException}. |
| 121 | + * Default true. |
| 122 | + * @param defaultRequeue true to requeue by default. |
| 123 | + * @return the spec |
| 124 | + */ |
85 | 125 | public AmqpClientInboundGatewaySpec defaultRequeue(boolean defaultRequeue) { |
86 | 126 | this.target.setDefaultRequeue(defaultRequeue); |
87 | 127 | return this; |
88 | 128 | } |
89 | 129 |
|
| 130 | + /** |
| 131 | + * Set a duration for how long to wait for all the consumers to shoutdown successfully on listener container stop. |
| 132 | + * Default 30 seconds. |
| 133 | + * @param gracefulShutdownPeriod the timeout to wait on stop. |
| 134 | + * @return the spec |
| 135 | + */ |
90 | 136 | public AmqpClientInboundGatewaySpec gracefulShutdownPeriod(Duration gracefulShutdownPeriod) { |
91 | 137 | this.target.setGracefulShutdownPeriod(gracefulShutdownPeriod); |
92 | 138 | return this; |
93 | 139 | } |
94 | 140 |
|
| 141 | + /** |
| 142 | + * Each queue runs in its own consumer; set this property to create multiple |
| 143 | + * consumers for each queue. |
| 144 | + * Can be treated as {@code concurrency}, but per queue. |
| 145 | + * @param consumersPerQueue the consumers per queue. |
| 146 | + * @return the spec |
| 147 | + */ |
95 | 148 | public AmqpClientInboundGatewaySpec consumersPerQueue(int consumersPerQueue) { |
96 | 149 | this.target.setConsumersPerQueue(consumersPerQueue); |
97 | 150 | return this; |
98 | 151 | } |
99 | 152 |
|
| 153 | + /** |
| 154 | + * Set a {@link MessageConverter} to replace the default |
| 155 | + * {@link org.springframework.amqp.support.converter.SimpleMessageConverter}. |
| 156 | + * If set to null, an AMQP message is sent as is into a message payload. |
| 157 | + * And a reply message has to return an AMQP message as its payload. |
| 158 | + * @param messageConverter the {@link MessageConverter} to use or null. |
| 159 | + * @return the spec |
| 160 | + */ |
100 | 161 | public AmqpClientInboundGatewaySpec messageConverter(@Nullable MessageConverter messageConverter) { |
101 | 162 | this.target.setMessageConverter(messageConverter); |
102 | 163 | return this; |
103 | 164 | } |
104 | 165 |
|
| 166 | + /** |
| 167 | + * Set an {@link AmqpHeaderMapper} to map request and reply headers. |
| 168 | + * @param headerMapper the {@link AmqpHeaderMapper} to use. |
| 169 | + * @return the spec |
| 170 | + */ |
105 | 171 | public AmqpClientInboundGatewaySpec headerMapper(AmqpHeaderMapper headerMapper) { |
106 | 172 | this.target.setHeaderMapper(headerMapper); |
107 | 173 | return this; |
108 | 174 | } |
109 | 175 |
|
| 176 | + /** |
| 177 | + * Set an {@link ReplyPostProcessor} to modify reply AMQP message before producing. |
| 178 | + * @param replyPostProcessor the {@link ReplyPostProcessor} to use. |
| 179 | + * @return the spec |
| 180 | + */ |
110 | 181 | public AmqpClientInboundGatewaySpec replyPostProcessor(ReplyPostProcessor replyPostProcessor) { |
111 | 182 | this.target.setReplyPostProcessor(replyPostProcessor); |
112 | 183 | return this; |
113 | 184 | } |
114 | 185 |
|
| 186 | + /** |
| 187 | + * Set an exchange for publishing reply. |
| 188 | + * Mutually exclusive with {@link #replyQueue(String)}. |
| 189 | + * If neither is set, the {@code replyTo} property from the request message |
| 190 | + * is used to determine where to produce a reply. |
| 191 | + * @param exchange the exchange to send a reply. |
| 192 | + * @return the spec |
| 193 | + */ |
115 | 194 | public AmqpClientInboundGatewaySpec replyExchange(String exchange) { |
116 | 195 | this.target.setReplyExchange(exchange); |
117 | 196 | return this; |
118 | 197 | } |
119 | 198 |
|
| 199 | + /** |
| 200 | + * Set a routing key for publishing reply. |
| 201 | + * Used only together with {@link #replyExchange(String)}. |
| 202 | + * If neither is set, the {@code replyTo} property from the request message |
| 203 | + * is used to determine where to produce a reply. |
| 204 | + * @param routingKey the routing key to send a reply. |
| 205 | + * @return the spec |
| 206 | + */ |
120 | 207 | public AmqpClientInboundGatewaySpec replyRoutingKey(String routingKey) { |
121 | 208 | this.target.setReplyRoutingKey(routingKey); |
122 | 209 | return this; |
123 | 210 | } |
124 | 211 |
|
| 212 | + /** |
| 213 | + * Set a queue for publishing reply. |
| 214 | + * Mutually exclusive with {@link #replyExchange(String)}. |
| 215 | + * If neither is set, the {@code replyTo} property from the request message |
| 216 | + * is used to determine where to produce a reply. |
| 217 | + * @param queue the queue to send a reply. |
| 218 | + * @return the spec |
| 219 | + */ |
125 | 220 | public AmqpClientInboundGatewaySpec replyQueue(String queue) { |
126 | 221 | this.target.setReplyQueue(queue); |
127 | 222 | return this; |
|
0 commit comments