-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from fp-in-bo/activemq
Add support for activemq-artemis
- Loading branch information
Showing
20 changed files
with
595 additions
and
481 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
active-mq-artemis/src/main/scala/jms4s/activemq/activeMQ.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package jms4s.activemq | ||
|
||
import cats.data.NonEmptyList | ||
import cats.effect.{ Blocker, Resource, Sync } | ||
import cats.implicits._ | ||
import io.chrisdavenport.log4cats.Logger | ||
import jms4s.jms.JmsConnection | ||
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory | ||
|
||
object activeMQ { | ||
|
||
case class Config( | ||
endpoints: NonEmptyList[Endpoint], | ||
username: Option[Username] = None, | ||
password: Option[Password] = None, | ||
clientId: ClientId | ||
) | ||
case class Username(value: String) extends AnyVal | ||
case class Password(value: String) extends AnyVal | ||
case class Endpoint(host: String, port: Int) | ||
case class ClientId(value: String) extends AnyVal | ||
|
||
def makeConnection[F[_]: Sync: Logger](config: Config, blocker: Blocker): Resource[F, JmsConnection[F]] = | ||
for { | ||
connection <- Resource.make( | ||
Logger[F].info(s"Opening Connection to MQ at ${hosts(config.endpoints)}...") *> | ||
Sync[F].delay { | ||
val factory = new ActiveMQConnectionFactory(hosts(config.endpoints)) | ||
factory.setClientID(config.clientId.value) | ||
|
||
val connection = config.username.fold(factory.createConnection)( | ||
username => | ||
factory.createConnection(username.value, config.password.map(_.value).getOrElse("")) | ||
) | ||
|
||
connection.start() | ||
connection | ||
} | ||
)( | ||
c => | ||
Logger[F].info(s"Closing Connection $c to MQ at ${hosts(config.endpoints)}...") *> | ||
Sync[F].delay(c.close()) *> | ||
Logger[F].info(s"Closed Connection $c to MQ at ${hosts(config.endpoints)}.") | ||
) | ||
_ <- Resource.liftF(Logger[F].info(s"Opened connection $connection.")) | ||
} yield new JmsConnection[F](connection, blocker) | ||
|
||
private def hosts(endpoints: NonEmptyList[Endpoint]): String = | ||
endpoints.map(e => s"tcp://${e.host}:${e.port}").toList.mkString(",") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.