/** * 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, 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()); }
fetcher.setStartMessage(lastMessageId, false); } else { fetcher.setStartTime(0L);
fetcher.setStartMessage(lastMessageId, false); } else { fetcher.setStartTime(0L);
@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()); }
Transaction transaction = new Transaction(3L, 3L, new long[0], new long[]{2L}, 2L); try (CloseableIterator<RawMessage> iterator = client.prepareFetch(topicId) .setStartTime(0) .setTransaction(transaction) .fetch()) { .setStartTime(new MessageId(startMessageId) .getPublishTimestamp()) .setLimit(2)