diff --git a/core/src/main/scala/jms4s/jms/JmsContext.scala b/core/src/main/scala/jms4s/jms/JmsContext.scala index 5b6493d4..6ca5839e 100644 --- a/core/src/main/scala/jms4s/jms/JmsContext.scala +++ b/core/src/main/scala/jms4s/jms/JmsContext.scala @@ -51,8 +51,11 @@ class JmsContext[F[_]: Async: Logger](private val context: JMSContext) { def send(destinationName: DestinationName, message: JmsMessage): F[Unit] = for { destination <- createDestination(destinationName) + _ <- Logger[F].debug(s"Creating producer") p <- Sync[F].blocking(context.createProducer()) + _ <- Logger[F].debug(s"Sending message $message to destination: $destinationName") _ <- Sync[F].blocking(p.send(destination.wrapped, message.wrapped)) + _ <- Logger[F].debug(s"Sent message $message to destination: $destinationName") } yield () def send(destinationName: DestinationName, message: JmsMessage, delay: FiniteDuration): F[Unit] = @@ -86,10 +89,12 @@ class JmsContext[F[_]: Async: Logger](private val context: JMSContext) { def rollback: F[Unit] = Sync[F].blocking(context.rollback()) private def createQueue(queue: QueueName): F[JmsQueue] = - Sync[F].blocking(context.createQueue(queue.value)).map(new JmsQueue(_)) + Logger[F].debug(s"Creating Queue $queue") *> + Sync[F].blocking(context.createQueue(queue.value)).map(new JmsQueue(_)) private def createTopic(topicName: TopicName): F[JmsTopic] = - Sync[F].blocking(context.createTopic(topicName.value)).map(new JmsTopic(_)) + Logger[F].debug(s"Creating Topic $topicName") *> + Sync[F].blocking(context.createTopic(topicName.value)).map(new JmsTopic(_)) def createDestination(destination: DestinationName): F[JmsDestination] = destination match { case q: QueueName => createQueue(q).widen[JmsDestination] diff --git a/core/src/main/scala/jms4s/jms/JmsMessageConsumer.scala b/core/src/main/scala/jms4s/jms/JmsMessageConsumer.scala index d88aec5a..c54b4925 100644 --- a/core/src/main/scala/jms4s/jms/JmsMessageConsumer.scala +++ b/core/src/main/scala/jms4s/jms/JmsMessageConsumer.scala @@ -25,10 +25,11 @@ import cats.effect.{ Async, Spawn, Sync } import cats.syntax.all._ import scala.concurrent.duration.FiniteDuration +import org.typelevel.log4cats.Logger import javax.jms.JMSConsumer -class JmsMessageConsumer[F[_]: Async] private[jms4s] ( +class JmsMessageConsumer[F[_]: Async: Logger] private[jms4s] ( private[jms4s] val wrapped: JMSConsumer, private[jms4s] val pollingInterval: FiniteDuration ) { @@ -37,8 +38,12 @@ class JmsMessageConsumer[F[_]: Async] private[jms4s] ( for { recOpt <- Sync[F].blocking(Option(wrapped.receiveNoWait())) rec <- recOpt match { - case Some(message) => Sync[F].pure(new JmsMessage(message)) - case None => Spawn[F].cede >> Async[F].sleep(pollingInterval) >> receiveJmsMessage + case Some(message) => + Sync[F].pure(new JmsMessage(message)) <* Logger[F].debug(s"Received message: $message") + case None => + Spawn[F].cede >> Async[F].sleep(pollingInterval) >> Logger[F].trace( + s"JmsMessageConsumer#receiveJmsMessage slept: $pollingInterval" + ) >> receiveJmsMessage } } yield rec }