private void tryBeginTxn(Producer<?, ?> producer) { try { producer.beginTransaction(); } catch (ProducerFencedException e) { logger.warn("Unable to begin transaction", e); throw new EventPublicationFailedException( "Event publication failed: Exception occurred while starting kafka transaction", e); } }
private void tryBeginTxn(Producer<?, ?> producer) { try { producer.beginTransaction(); } catch (ProducerFencedException e) { logger.warn("Unable to begin transaction", e); throw new EventPublicationFailedException( "Event publication failed: Exception occurred while starting kafka transaction", e); } }
@Override public Optional<EventMessage<?>> readAMQPMessage(byte[] messageBody, Map<String, Object> headers) { try { EventMessageReader in = new EventMessageReader(new DataInputStream(new ByteArrayInputStream(messageBody)), serializer); return Optional.of(in.readEventMessage()); } catch (IOException e) { // ByteArrayInputStream doesn't throw IOException... anyway... throw new EventPublicationFailedException("Failed to deserialize an EventMessage", e); } }
private byte[] asByteArray(EventMessage event) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); EventMessageWriter outputStream = new EventMessageWriter(new DataOutputStream(baos), serializer); outputStream.writeEventMessage(event); return baos.toByteArray(); } catch (IOException e) { // ByteArrayOutputStream doesn't throw IOException... anyway... throw new EventPublicationFailedException("Failed to serialize an EventMessage", e); } } }
private void tryCommit(Producer<?, ?> producer, Map<? super EventMessage<?>, MonitorCallback> monitorCallbacks) { try { producer.commitTransaction(); monitorCallbacks.forEach((k, v) -> v.reportSuccess()); } catch (ProducerFencedException e) { logger.warn("Unable to commit transaction", e); monitorCallbacks.forEach((k, v) -> v.reportFailure(e)); throw new EventPublicationFailedException( "Event publication failed: Exception occurred while committing kafka transaction", e); } }
private void tryCommit(Producer<?, ?> producer, Map<? super EventMessage<?>, MonitorCallback> monitorCallbacks) { try { producer.commitTransaction(); monitorCallbacks.forEach((k, v) -> v.reportSuccess()); } catch (ProducerFencedException e) { logger.warn("Unable to commit transaction", e); monitorCallbacks.forEach((k, v) -> v.reportFailure(e)); throw new EventPublicationFailedException( "Event publication failed: Exception occurred while committing kafka transaction", e); } }
unitOfWork.onCommit(u -> { if ((isTransactional || waitForAck) && !channel.isOpen()) { throw new EventPublicationFailedException( "Unable to Commit UnitOfWork changes to AMQP: Channel is closed.", channel.getCloseReason()); channel.waitForConfirmsOrDie(publisherAckTimeout); } catch (IOException ex) { throw new EventPublicationFailedException( "Failed to receive acknowledgements for all events", ex); } catch (TimeoutException ex) { throw new EventPublicationFailedException( "Timeout while waiting for publisher acknowledgements", ex); tryRollback(channel); throw new EventPublicationFailedException("Failed to dispatch Events to the Message Broker.", e); } catch (ShutdownSignalException e) { throw new EventPublicationFailedException("Failed to dispatch Events to the Message Broker.", e); } catch (InterruptedException e) { logger.warn("Interrupt received when waiting for message confirms.");