-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
producer.send now returns the JMS Message ID #363
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,17 +35,17 @@ trait JmsProducer[F[_]] { | |
|
||
def sendN( | ||
messageFactory: MessageFactory[F] => F[NonEmptyList[(JmsMessage, DestinationName)]] | ||
): F[Unit] | ||
): F[NonEmptyList[Option[String]]] | ||
|
||
def sendNWithDelay( | ||
messageFactory: MessageFactory[F] => F[NonEmptyList[(JmsMessage, (DestinationName, Option[FiniteDuration]))]] | ||
): F[Unit] | ||
): F[NonEmptyList[Option[String]]] | ||
|
||
def sendWithDelay( | ||
messageFactory: MessageFactory[F] => F[(JmsMessage, (DestinationName, Option[FiniteDuration]))] | ||
): F[Unit] | ||
): F[Option[String]] | ||
|
||
def send(messageFactory: MessageFactory[F] => F[(JmsMessage, DestinationName)]): F[Unit] | ||
def send(messageFactory: MessageFactory[F] => F[(JmsMessage, DestinationName)]): F[Option[String]] | ||
|
||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe adding some "general" docs to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay I can add something... |
||
|
@@ -78,60 +78,63 @@ object JmsProducer { | |
|
||
private[jms4s] def make[F[_]: Async]( | ||
context: JmsContext[F], | ||
concurrencyLevel: Int | ||
concurrencyLevel: Int, | ||
disableMessageId: Boolean = false | ||
): Resource[F, JmsProducer[F]] = | ||
for { | ||
pool <- ContextPool.create(context, concurrencyLevel) | ||
} yield new JmsProducer[F] { | ||
|
||
override def sendN( | ||
f: MessageFactory[F] => F[NonEmptyList[(JmsMessage, DestinationName)]] | ||
): F[Unit] = | ||
): F[NonEmptyList[Option[String]]] = | ||
pool.acquireAndUseContext { | ||
case (ctx, mf) => | ||
for { | ||
messagesWithDestinations <- f(mf) | ||
_ <- messagesWithDestinations.traverse_ { | ||
case (message, destinationName) => ctx.send(destinationName, message) | ||
} | ||
} yield () | ||
messageIds <- messagesWithDestinations.traverse { | ||
case (message, destinationName) => ctx.send(destinationName, message, disableMessageId) | ||
} | ||
} yield messageIds | ||
} | ||
|
||
override def sendNWithDelay( | ||
f: MessageFactory[F] => F[NonEmptyList[(JmsMessage, (DestinationName, Option[FiniteDuration]))]] | ||
): F[Unit] = | ||
): F[NonEmptyList[Option[String]]] = | ||
pool.acquireAndUseContext { | ||
case (ctx, mf) => | ||
for { | ||
messagesWithDestinationsAndDelayes <- f(mf) | ||
_ <- messagesWithDestinationsAndDelayes.traverse_ { | ||
case (message, (destinatioName, duration)) => | ||
duration.fold(ctx.send(destinatioName, message))(delay => | ||
ctx.send(destinatioName, message, delay) | ||
) | ||
} | ||
|
||
} yield () | ||
messageIds <- messagesWithDestinationsAndDelayes.traverse { | ||
case (message, (destinatioName, duration)) => | ||
duration.fold(ctx.send(destinatioName, message, disableMessageId))(delay => | ||
ctx.send(destinatioName, message, delay, disableMessageId) | ||
) | ||
} | ||
|
||
} yield messageIds | ||
} | ||
|
||
override def sendWithDelay( | ||
f: MessageFactory[F] => F[(JmsMessage, (DestinationName, Option[FiniteDuration]))] | ||
): F[Unit] = | ||
): F[Option[String]] = | ||
pool.acquireAndUseContext { | ||
case (ctx, mf) => | ||
for { | ||
(message, (destinationName, delay)) <- f(mf) | ||
_ <- delay.fold(ctx.send(destinationName, message))(delay => ctx.send(destinationName, message, delay)) | ||
} yield () | ||
messageId <- delay.fold(ctx.send(destinationName, message, disableMessageId))(delay => | ||
ctx.send(destinationName, message, delay, disableMessageId) | ||
) | ||
} yield messageId | ||
} | ||
|
||
override def send(f: MessageFactory[F] => F[(JmsMessage, DestinationName)]): F[Unit] = | ||
override def send(f: MessageFactory[F] => F[(JmsMessage, DestinationName)]): F[Option[String]] = | ||
pool.acquireAndUseContext { | ||
case (ctx, mf) => | ||
for { | ||
(message, destination) <- f(mf) | ||
_ <- ctx.send(destination, message) | ||
} yield () | ||
messageId <- ctx.send(destination, message, disableMessageId) | ||
} yield messageId | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -341,12 +341,14 @@ trait JmsClientSpec extends AsyncFreeSpec with AsyncIOSpec with Jms4sBaseSpec { | |
res.use { | ||
case (producer, consumer, bodies, messages) => | ||
for { | ||
_ <- messages.toNel.fold(IO.unit)(ms => producer.sendN(messageFactory(ms, topicName1))) | ||
messageIds <- messages.toNel.fold(IO.pure(List.empty[Option[String]]))(ms => | ||
producer.sendN(messageFactory(ms, topicName1)).map(_.toList) | ||
) | ||
_ <- logger.info(s"Pushed ${messages.size} messages.") | ||
_ <- logger.info(s"Consumer to Producer started.\nCollecting messages from output queue...") | ||
received <- Ref.of[IO, Set[String]](Set()) | ||
receivedMessages <- receiveUntil(consumer, received, nMessages).timeout(timeout) >> received.get | ||
} yield assert(receivedMessages == bodies) | ||
} yield assert(messages.size == messageIds.size && receivedMessages == bodies) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right now the |
||
} | ||
} | ||
|
||
|
@@ -459,7 +461,7 @@ trait JmsClientSpec extends AsyncFreeSpec with AsyncIOSpec with Jms4sBaseSpec { | |
_ <- (0 until poolSize).toList.traverse_ { _ => | ||
producer | ||
.send(_ => IO.raiseError(new RuntimeException("failed producing"))) | ||
.handleErrorWith(logger.error(_)("")) | ||
.handleErrorWith(logger.error(_)("").map(_ => None)) | ||
} | ||
_ <- producer | ||
.send(messageFactory(message, outputQueueName1)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can simplify this(and the others) return type with a simple
List[String]
returnig a
NonEmptyList
withOption
s inside(that can be None) does not make a lot of sense to me :/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@faustin0 Do you want me to do that to be able to get this PR merged, or should this be done in a future PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamretter can also be in a future PR but, being a change in a public api, maybe is better to "fix" now the return type of these methods. What do you think?