0

I have a AMQP Source and AMQP Sink with Declarations:

List<Declaration> declarations = new ArrayList<Declaration>() {{
      add(QueueDeclaration.create(sourceExchangeName));
      add(BindingDeclaration.create(sourceExchangeName, sourceExchangeName).withRoutingKey(sourceRoutingKey));
    }};

amqpSource = AmqpSource
    .committableSource(
        NamedQueueSourceSettings.create(connectionProvider, sourceExchangeName)
            .withDeclarations(declarations),
        bufferSize);

AmqpWriteSettings amqpWriteSettings = AmqpWriteSettings.create(connectionProvider)
    .withExchange("DEST_XCHANGE")
    .withRoutingKey("ROUTE123")
    .withDeclaration(ExchangeDeclaration.create(destinationExchangeName,
        BuiltinExchangeType.DIRECT.getType()));

amqpSink = AmqpSink.create(amqpWriteSettings);

And then I have a flow..

amqpSource.map(doSomething).async().map(doSomethingElse).async().to(amqpSink)

Now, after i started the app, the messages were sent to source queue was not getting consumed. I later found out that this was due to errors that occurred during declarations. (i.e., it worked fine when I removed the .withDeclarations(..) in the Source and Sink settings.

So my questions:

  1. How to detect if the AMQP Source and Sink are up and running fine?
  2. How to ignore declaration exceptions?
  3. If any exception occurs, how can I know and make the system fail?
Jerald Baker
  • 1,121
  • 1
  • 12
  • 48

1 Answers1

1

To answer 1 and 3, the AmqpSink materializes a CompletionStage<Done> that you would have to keep, and handle (register some callback functions on) to observe failure and completion of the stream. In the docs sample we block on that completion stage which is not good in production code (https://doc.akka.io/docs/alpakka/current/amqp.html#with-sink), that's probably because the sample is included in one of the Alpakka tests. Prefer the usual CompletionStage callback/transformation methods instead (see for example this introduction).

The CompletionStage will fail when an error happens, when the stream is materialized/starting up or during the processing of elements, alternatively complete once the source reaches the end and each element has gone through your flow into the sink. That means that for starting up the stream, if it does not pretty quickly fail it is running.

For question 2 not sure if it is possible to ignore the declaration exceptions, it could be that those always fail the connection.

johanandren
  • 11,249
  • 1
  • 25
  • 30
  • when I use a AmqpFlow for writing and then do some more mappings.. and I do a Sink.Ignore at the end. How can I detect failures in that case? – Jerald Baker May 18 '20 at 11:07
  • A failure in the flow will go downstream and end up in the materialized value of the `Sink.ignore`, so just make sure to hang on to that. – johanandren May 19 '20 at 16:49
  • Thank you. So this means when the steam's completion stage completes, the stream is done and not running anymore. thank you! – Jerald Baker May 20 '20 at 09:18