forked from rabbitmq/rabbitmq-stream-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageHandler.java
96 lines (86 loc) · 2.77 KB
/
MessageHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) 2020-2022 VMware, Inc. or its affiliates. All rights reserved.
//
// This software, the RabbitMQ Stream Java client library, is dual-licensed under the
// Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").
// For the MPL, please see LICENSE-MPL-RabbitMQ. For the ASL,
// please see LICENSE-APACHE2.
//
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
// either express or implied. See the LICENSE file for specific language governing
// rights and limitations of this software.
//
// If you have any questions regarding licensing, please contact us at
package com.rabbitmq.stream;
/**
* Callback API for inbound messages.
*
* @see ConsumerBuilder#messageHandler(MessageHandler)
* @see Consumer
*/
public interface MessageHandler {
/**
* Callback for an inbound message.
*
* @param context context on the message
* @param message the message
*/
void handle(Context context, Message message);
/** Information about the message. */
interface Context {
/**
* The offset of the message in the stream.
*
* @return the offset of the current message
*/
long offset();
/**
* Shortcut to send a store order for the message offset.
*
* @see Consumer#store(long)
*/
void storeOffset();
/**
* The timestamp of the message chunk.
*
* @return the timestamp of the message chunk
*/
long timestamp();
/**
* The ID (offset) of the committed chunk (block of messages) in the stream.
*
* <p>It is the offset of the first message in the last chunk confirmed by a quorum of the
* stream cluster members (leader and replicas).
*
* <p>The committed chunk ID is a good indication of what the last offset of a stream can be at
* a given time. The value can be stale as soon as the application reads it though, as the
* committed chunk ID for a stream that is published to changes all the time.
*
* <p>This requires RabbitMQ 3.11 or more. The method always returns 0 otherwise.
*
* @return committed chunk ID in this stream
* @see StreamStats#committedChunkId()
*/
long committedChunkId();
/**
* The stream the message comes from.
*
* @return the stream the message comes from
*/
String stream();
/**
* The consumer that receives the message.
*
* @return the consumer instance
* @see Consumer#store(long)
*/
Consumer consumer();
/**
* Marks this message as handled
*
* @return Whether the message was marked as handled (returning {@code true})
* or was not found (either because it was already marked as handled, or wasn't tracked)
*/
boolean markHandled();
}
}