The IronMQ connector provides an Akka stream source and sink to connect to the IronMQ queue.
IronMQ is a simple point-to-point queue, but it is possible to implement a fan-out semantic by configure the queue as push queue and set other queue as subscribers. More information about that could be found on IronMQ documentation
IronMQ can be used either in cloud or on-premise. Either way you need a authentication token and a project ID. These can be set in the application.conf file.
sourcealpakka.ironmq {// The IronMg endpoint. It may vary due to availability zone and region.
endpoint ="https://mq-aws-eu-west-1-1.iron.io"
credentials {// The IronMq project id// project-id =// The IronMq auth token// token =}
consumer {// This is the max number of message to fetch from IronMq.
buffer-max-size =100// This is the threshold where fech other messages from IronMq
buffer-min-size =25// This is the time interval between each poll loop
fetch-interval =250 milliseconds
// This is the amount of time the IronMq client will wait for a message to be available in the queue
poll-timeout =0// This is the amount of time a fetched message will be not available to other consumers
reservation-timeout =30 seconds
}}
The consumer is poll-based. It will poll every fetch-interval milliseconds, waiting for poll-timeout milliseconds to consume new messages and will push those downstream.
It supports both at-most-once and at-least-once semantics. In the first case the messages are deleted straight away after been fetched. In the latter case the messages piggy back a Committable object that should be used to commit the message. Committing the message will cause the message to be deleted from the queue.
sourceimport akka.stream.alpakka.ironmq.Message
val source:Source[Message,NotUsed]=IronMqConsumer.atMostOnceSource(queueName, ironMqSettings)
val receivedMessages:Future[immutable.Seq[Message]]= source
.take(100).runWith(Sink.seq)
sourceimport akka.stream.alpakka.ironmq.scaladsl.CommittableMessageimport akka.stream.alpakka.ironmq.Message
val source:Source[CommittableMessage,NotUsed]=IronMqConsumer.atLeastOnceSource(queueName, ironMqSettings)
val businessLogic:Flow[CommittableMessage,CommittableMessage,NotUsed]=Flow[CommittableMessage]// do something useful with the received messages
val receivedMessages:Future[immutable.Seq[Message]]= source
.take(100).via(businessLogic).mapAsync(1)(m => m.commit().map(_ => m.message)).runWith(Sink.seq)
sourceimport akka.stream.alpakka.ironmq.*;import akka.stream.alpakka.ironmq.javadsl.*;Source<CommittableMessage,NotUsed> source =IronMqConsumer.atLeastOnceSource(queueName, ironMqSettings);Flow<CommittableMessage,CommittableMessage,NotUsed> businessLogic =Flow.of(CommittableMessage.class);// do something useful with the received messagesCompletionStage<List<Message>> receivedMessages =
source
.take(5).via(businessLogic).mapAsync(1, m -> m.commit().thenApply(d -> m.message())).runWith(Sink.seq(), materializer);
Producer
The producer is very trivial at this time, it does not provide any batching mechanism, but sends messages to IronMq as soon as they arrive to the stage.
The producer is instantiated using the IronMqProducerIronMqProducer. It provides methods to obtain either a Flow[PushMessage, Messages.Id, NotUsed]Flow<PushMessage, Messages.Id, NotUsed> or a Sink[PushMessage, NotUsed]Sink<PushMessage, NotUsed>.
Flow
The PushMessage allows to specify the delay per individual message. The message expiration is set a queue level.
When using the Flow the returned Messages.IdsString contains the ID of the pushed message, that can be used to manipulate the message. For each PushMessage from the upstream you will have exactly one Message.IdString in downstream in the same order.
sourceimport akka.stream.alpakka.ironmq.{Message,PushMessage}
val messages: immutable.Seq[String]=(1 to messageCount).map(i => s"test-$i")
val producedIds:Future[immutable.Seq[Message.Id]]=Source(messages).map(PushMessage(_)).via(IronMqProducer.flow(queueName, ironMqSettings)).runWith(Sink.seq)
The producer also provides a committable aware Flow/Sink as Flow[(PushMessage, Committable), Message.Id, NotUsed]Flow<CommittablePushMessage<Committable>, String, NotUsed>. It can be used to consume a Flow from an IronMQ consumer or any other source that provides a commit mechanism.
sourceimport akka.stream.alpakka.ironmq.{Message,PushMessage}
val messages: immutable.Seq[String]=(1 to messageCount).map(i => s"test-$i")
val producedIds:Future[Done]=Source(messages).map(PushMessage(_)).runWith(IronMqProducer.sink(queueName, ironMqSettings))