/** * Creates a {@link CloseableIterator} of {@link RawMessage} based on the given fetch request. */ private CloseableIterator<RawMessage> fetchMessages(GenericRecord fetchRequest, TopicId topicId) throws IOException, TopicNotFoundException { MessageFetcher fetcher = messagingService.prepareFetch(topicId); Object startFrom = fetchRequest.get("startFrom"); if (startFrom != null) { if (startFrom instanceof ByteBuffer) { // start message id is specified fetcher.setStartMessage(Bytes.toBytes((ByteBuffer) startFrom), (Boolean) fetchRequest.get("inclusive")); } else if (startFrom instanceof Long) { // start by timestamp is specified fetcher.setStartTime((Long) startFrom); } else { // This shouldn't happen as it's guaranteed by the schema LOG.warn("Ignore unrecognized type for startFrom. Type={}, Value={}", startFrom.getClass(), startFrom); } } Integer limit = (Integer) fetchRequest.get("limit"); if (limit != null) { fetcher.setLimit(limit); } ByteBuffer encodedTx = (ByteBuffer) fetchRequest.get("transaction"); if (encodedTx != null) { fetcher.setTransaction(TRANSACTION_CODEC.decode(ByteBuffers.getByteArray(encodedTx))); } return fetcher.fetch(); }
/** * Creates a {@link CloseableIterator} of {@link RawMessage} based on the given fetch request. */ private CloseableIterator<RawMessage> fetchMessages(GenericRecord fetchRequest, TopicId topicId) throws IOException, TopicNotFoundException { MessageFetcher fetcher = messagingService.prepareFetch(topicId); Object startFrom = fetchRequest.get("startFrom"); if (startFrom != null) { if (startFrom instanceof ByteBuffer) { // start message id is specified fetcher.setStartMessage(Bytes.toBytes((ByteBuffer) startFrom), (Boolean) fetchRequest.get("inclusive")); } else if (startFrom instanceof Long) { // start by timestamp is specified fetcher.setStartTime((Long) startFrom); } else { // This shouldn't happen as it's guaranteed by the schema LOG.warn("Ignore unrecognized type for startFrom. Type={}, Value={}", startFrom.getClass(), startFrom); } } Integer limit = (Integer) fetchRequest.get("limit"); if (limit != null) { fetcher.setLimit(limit); } ByteBuffer encodedTx = (ByteBuffer) fetchRequest.get("transaction"); if (encodedTx != null) { fetcher.setTransaction(TRANSACTION_CODEC.decode(ByteBuffers.getByteArray(encodedTx))); } return fetcher.fetch(); }
@Override public CloseableIterator<Message> fetch(String namespace, String topic, int limit, @Nullable String afterMessageId) throws IOException, TopicNotFoundException { co.cask.cdap.messaging.MessageFetcher fetcher = messagingService .prepareFetch(new NamespaceId(namespace).topic(topic)) .setLimit(limit); if (afterMessageId != null) { fetcher.setStartMessage(Bytes.fromHexString(afterMessageId), false); } if (transaction != null) { fetcher.setTransaction(transaction); } return new MessageIterator(fetcher.fetch()); }
@Override public CloseableIterator<Message> fetch(String namespace, String topic, int limit, @Nullable String afterMessageId) throws IOException, TopicNotFoundException { co.cask.cdap.messaging.MessageFetcher fetcher = messagingService .prepareFetch(new NamespaceId(namespace).topic(topic)) .setLimit(limit); if (afterMessageId != null) { fetcher.setStartMessage(Bytes.fromHexString(afterMessageId), false); } if (transaction != null) { fetcher.setTransaction(transaction); } return new MessageIterator(fetcher.fetch()); }
@Override public CloseableIterator<Message> fetch(String namespace, String topic, int limit, long timestamp) throws IOException, TopicNotFoundException { co.cask.cdap.messaging.MessageFetcher fetcher = messagingService .prepareFetch(new NamespaceId(namespace).topic(topic)) .setLimit(limit) .setStartTime(timestamp); if (transaction != null) { fetcher.setTransaction(transaction); } return new MessageIterator(fetcher.fetch()); }
@Override public CloseableIterator<Message> fetch(String namespace, String topic, int limit, long timestamp) throws IOException, TopicNotFoundException { co.cask.cdap.messaging.MessageFetcher fetcher = messagingService .prepareFetch(new NamespaceId(namespace).topic(topic)) .setLimit(limit) .setStartTime(timestamp); if (transaction != null) { fetcher.setTransaction(transaction); } return new MessageIterator(fetcher.fetch()); }
try (CloseableIterator<RawMessage> iterator = client.prepareFetch(topicId) .setStartTime(0) .setTransaction(transaction) .fetch()) { Iterators.addAll(txMessages, iterator); try (CloseableIterator<RawMessage> iterator = client.prepareFetch(topicId) .setStartMessage(startMessageId, false) .setTransaction(transaction) .fetch()) { Assert.assertFalse(iterator.hasNext()); try (CloseableIterator<RawMessage> iterator = client.prepareFetch(topicId) .setStartMessage(startMessageId, false) .setTransaction(transaction) .fetch()) { messages.clear(); try (CloseableIterator<RawMessage> iterator = client.prepareFetch(topicId) .setStartMessage(startMessageId, false) .setTransaction(transaction) .fetch()) { messages.clear();