PendingStoreRequest(StoreRequest originalRequest, TopicMetadata topicMetadata) { super(originalRequest.getTopicId(), originalRequest.isTransactional(), originalRequest.getTransactionWritePointer()); this.originalRequest = originalRequest; this.metadata = topicMetadata; }
@Override public boolean hasPayload() { return originalRequest.hasPayload(); }
@Override public Iterator<byte[]> iterator() { return originalRequest.iterator(); }
@POST @Path("/store") public void store(FullHttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception { TopicId topicId = new NamespaceId(namespace).topic(topic); StoreRequest storeRequest = createStoreRequest(topicId, request); // It must be transactional with payload for store request if (!storeRequest.isTransactional() || !storeRequest.hasPayload()) { throw new BadRequestException("Store request must be transactional with payload. Topic: " + topicId); } messagingService.storePayload(storeRequest); responder.sendStatus(HttpResponseStatus.OK); }
@Override public void storePayload(StoreRequest request) throws TopicNotFoundException, IOException { try { TopicMetadata metadata = topicCache.get(request.getTopicId()); payloadTableWriterCache.get(request.getTopicId()).persist(request, metadata); } catch (ExecutionException e) { Throwable cause = Objects.firstNonNull(e.getCause(), e); Throwables.propagateIfPossible(cause, TopicNotFoundException.class, IOException.class); throw Throwables.propagate(e); } }
/** * Converts the payloads carried by the given {@link StoreRequest} into a {@link List} of {@link ByteBuffer}, * which is needed by the avro record. */ private List<ByteBuffer> convertPayloads(StoreRequest request) { return StreamSupport.stream(request.spliterator(), false).map(ByteBuffer::wrap).collect(Collectors.toList()); }
@POST @Path("/store") public void store(FullHttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception { TopicId topicId = new NamespaceId(namespace).topic(topic); StoreRequest storeRequest = createStoreRequest(topicId, request); // It must be transactional with payload for store request if (!storeRequest.isTransactional() || !storeRequest.hasPayload()) { throw new BadRequestException("Store request must be transactional with payload. Topic: " + topicId); } messagingService.storePayload(storeRequest); responder.sendStatus(HttpResponseStatus.OK); }
@Override public void storePayload(StoreRequest request) throws TopicNotFoundException, IOException { try { TopicMetadata metadata = topicCache.get(request.getTopicId()); payloadTableWriterCache.get(request.getTopicId()).persist(request, metadata); } catch (ExecutionException e) { Throwable cause = Objects.firstNonNull(e.getCause(), e); Throwables.propagateIfPossible(cause, TopicNotFoundException.class, IOException.class); throw Throwables.propagate(e); } }
/** * Converts the payloads carried by the given {@link StoreRequest} into a {@link List} of {@link ByteBuffer}, * which is needed by the avro record. */ private List<ByteBuffer> convertPayloads(StoreRequest request) { return StreamSupport.stream(request.spliterator(), false).map(ByteBuffer::wrap).collect(Collectors.toList()); }
PendingStoreRequest(StoreRequest originalRequest, TopicMetadata topicMetadata) { super(originalRequest.getTopicId(), originalRequest.isTransactional(), originalRequest.getTransactionWritePointer()); this.originalRequest = originalRequest; this.metadata = topicMetadata; }
@POST @Path("/publish") public void publish(FullHttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception { TopicId topicId = new NamespaceId(namespace).topic(topic); StoreRequest storeRequest = createStoreRequest(topicId, request); // Empty payload is only allowed for transactional publish if (!storeRequest.isTransactional() && !storeRequest.hasPayload()) { throw new BadRequestException("Empty payload is only allowed for publishing transactional message. Topic: " + topicId); } // Publish the message and response with the rollback information RollbackDetail rollbackInfo = messagingService.publish(storeRequest); if (rollbackInfo == null) { // Non-tx publish doesn't have rollback info. responder.sendStatus(HttpResponseStatus.OK); return; } ByteBuf response = encodeRollbackDetail(rollbackInfo); responder.sendContent(HttpResponseStatus.OK, response, new DefaultHttpHeaders().set(HttpHeaderNames.CONTENT_TYPE, "avro/binary")); }
metricsCollector.increment("persist.failure", 1L); Throwables.propagateIfInstanceOf(pendingStoreRequest.getFailureCause(), IOException.class); throw new IOException("Unable to write message to " + storeRequest.getTopicId(), pendingStoreRequest.getFailureCause());
@Override public boolean hasPayload() { return originalRequest.hasPayload(); }
@Override public Iterator<byte[]> iterator() { return originalRequest.iterator(); }
@Nullable @Override public RollbackDetail publish(StoreRequest request) throws TopicNotFoundException, IOException { try { TopicMetadata metadata = topicCache.get(request.getTopicId()); if (request.isTransactional()) { ensureValidTxLifetime(request.getTransactionWritePointer()); } return messageTableWriterCache.get(request.getTopicId()).persist(request, metadata); } catch (ExecutionException e) { Throwable cause = Objects.firstNonNull(e.getCause(), e); Throwables.propagateIfPossible(cause, TopicNotFoundException.class, IOException.class); throw Throwables.propagate(e); } }
@POST @Path("/publish") public void publish(FullHttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception { TopicId topicId = new NamespaceId(namespace).topic(topic); StoreRequest storeRequest = createStoreRequest(topicId, request); // Empty payload is only allowed for transactional publish if (!storeRequest.isTransactional() && !storeRequest.hasPayload()) { throw new BadRequestException("Empty payload is only allowed for publishing transactional message. Topic: " + topicId); } // Publish the message and response with the rollback information RollbackDetail rollbackInfo = messagingService.publish(storeRequest); if (rollbackInfo == null) { // Non-tx publish doesn't have rollback info. responder.sendStatus(HttpResponseStatus.OK); return; } ByteBuf response = encodeRollbackDetail(rollbackInfo); responder.sendContent(HttpResponseStatus.OK, response, new DefaultHttpHeaders().set(HttpHeaderNames.CONTENT_TYPE, "avro/binary")); }
metricsCollector.increment("persist.failure", 1L); Throwables.propagateIfInstanceOf(pendingStoreRequest.getFailureCause(), IOException.class); throw new IOException("Unable to write message to " + storeRequest.getTopicId(), pendingStoreRequest.getFailureCause());
@Nullable @Override public RollbackDetail publish(StoreRequest request) throws TopicNotFoundException, IOException { try { TopicMetadata metadata = topicCache.get(request.getTopicId()); if (request.isTransactional()) { ensureValidTxLifetime(request.getTransactionWritePointer()); } return messageTableWriterCache.get(request.getTopicId()).persist(request, metadata); } catch (ExecutionException e) { Throwable cause = Objects.firstNonNull(e.getCause(), e); Throwables.propagateIfPossible(cause, TopicNotFoundException.class, IOException.class); throw Throwables.propagate(e); } }
boolean publish) throws IOException, TopicNotFoundException { GenericRecord record = new GenericData.Record(Schemas.V1.PublishRequest.SCHEMA); if (request.isTransactional()) { record.put("transactionWritePointer", request.getTransactionWritePointer()); TopicId topicId = request.getTopicId(); HttpRequest httpRequest = remoteClient.requestBuilder(HttpMethod.POST, createTopicPath(topicId) + "/" + writeType) .addHeader(HttpHeaders.CONTENT_TYPE, "avro/binary")
boolean publish) throws IOException, TopicNotFoundException { GenericRecord record = new GenericData.Record(Schemas.V1.PublishRequest.SCHEMA); if (request.isTransactional()) { record.put("transactionWritePointer", request.getTransactionWritePointer()); TopicId topicId = request.getTopicId(); HttpRequest httpRequest = remoteClient.requestBuilder(HttpMethod.POST, createTopicPath(topicId) + "/" + writeType) .addHeader(HttpHeaders.CONTENT_TYPE, "avro/binary")