private void streamMessages() {
System.out.format("Stream Messages%n");
MessageApi messageApi = marconiApi.getMessageApiForZoneAndClientAndQueue(ZONE, CONSUMER_ID, NAME);
MessageStream stream = messageApi.stream();
String marker = "";
while(stream.nextMarker().isPresent()) {
for (Message message: stream) {
Properties messageProps = loadStringProperties(message.getBody());
int messageNum = Integer.valueOf(messageProps.getProperty(MESSAGE_NUM));
System.out.format(" Read message %d%n", messageNum);
if (messageNum == 49) {
System.out.format(" Breaking at message %d%n", messageNum);
// Breaking here to illustrate how to resume using the marker below
break;
}
}
marker = stream.nextStreamOptions().getMarker();
stream = messageApi.stream(stream.nextStreamOptions());
}
stream = messageApi.stream(marker(marker));
while(stream.nextMarker().isPresent()) {
for (Message message: stream) {
Properties messageProps = loadStringProperties(message.getBody());
int messageNum = Integer.valueOf(messageProps.getProperty(MESSAGE_NUM));
System.out.format(" Read message %d%n", messageNum);
}
stream = messageApi.stream(stream.nextStreamOptions());
}
}