|
11 | 11 | import com.rabbitmq.client.amqp.Publisher; |
12 | 12 | import com.rabbitmq.client.amqp.impl.AmqpEnvironmentBuilder; |
13 | 13 |
|
14 | | -import java.nio.charset.StandardCharsets; |
15 | 14 | import java.time.Duration; |
16 | 15 |
|
| 16 | +import static java.nio.charset.StandardCharsets.UTF_8; |
| 17 | + |
17 | 18 | public class WebsiteDocumentation { |
18 | 19 |
|
19 | 20 | void environment() { |
@@ -48,7 +49,7 @@ void publishing() { |
48 | 49 |
|
49 | 50 | // create the message |
50 | 51 | Message message = publisher |
51 | | - .message("hello".getBytes(StandardCharsets.UTF_8)) |
| 52 | + .message("hello".getBytes(UTF_8)) |
52 | 53 | .messageId(1L); |
53 | 54 |
|
54 | 55 | // publish the message and deal with broker feedback |
@@ -326,4 +327,52 @@ void deactivateRecovery() { |
326 | 327 | .activated(false) |
327 | 328 | .connectionBuilder().build(); |
328 | 329 | } |
| 330 | + |
| 331 | + void propertyFilterExpressions() { |
| 332 | + Connection connection = null; |
| 333 | + Consumer consumer = connection.consumerBuilder() |
| 334 | + .stream().filter() |
| 335 | + .userId("John".getBytes(UTF_8)) |
| 336 | + .subject("&p:Order") |
| 337 | + .property("region", "emea") |
| 338 | + .stream().builder() |
| 339 | + .queue("my-queue") |
| 340 | + .messageHandler((ctx, msg ) -> { |
| 341 | + // message processing |
| 342 | + }) |
| 343 | + .build(); |
| 344 | + } |
| 345 | + |
| 346 | + void sqlFilterExpressions() { |
| 347 | + Connection connection = null; |
| 348 | + Consumer consumer = connection.consumerBuilder() |
| 349 | + .stream().filter() |
| 350 | + .sql("properties.user_id = 'John' AND " + |
| 351 | + "properties.subject LIKE 'Order%' AND " + |
| 352 | + "region = 'emea'") |
| 353 | + .stream().builder() |
| 354 | + .queue("my-queue") |
| 355 | + .messageHandler((ctx, msg ) -> { |
| 356 | + // message processing |
| 357 | + }) |
| 358 | + .build(); |
| 359 | + } |
| 360 | + |
| 361 | + void combinedFilterExpressions() { |
| 362 | + Connection connection = null; |
| 363 | + Consumer consumer = connection.consumerBuilder() |
| 364 | + .stream() |
| 365 | + .filterValues("order.created") |
| 366 | + .filter() |
| 367 | + .sql("p.subject = 'order.created' AND " + |
| 368 | + "p.creation_time > UTC() - 3600000 AND " + |
| 369 | + "region IN ('AMER', 'EMEA', 'APJ') AND " + |
| 370 | + "(h.priority > 4 OR price >= 99.99 OR premium_customer = TRUE)") |
| 371 | + .stream().builder() |
| 372 | + .queue("my-queue") |
| 373 | + .messageHandler((ctx, msg ) -> { |
| 374 | + // message processing |
| 375 | + }) |
| 376 | + .build(); |
| 377 | + } |
329 | 378 | } |
0 commit comments