-
Notifications
You must be signed in to change notification settings - Fork 0
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
PACT-709: First implementation of stub #1
base: main
Are you sure you want to change the base?
Changes from 2 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.bsp/ | ||
target/ | ||
/.idea/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 The National Archives, UK | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
JMS4s Request-Reply Stub | ||
# JMS4s Request-Reply Stub | ||
|
||
This stub service is designed to reply to JMS messages with stubbed data and is intended for use during development and testing of frontend services that rely on the response-reply message pattern. | ||
|
||
To start ElasticMQ in Docker run.. | ||
``` | ||
docker compose up -d | ||
``` | ||
..from the project root directory. | ||
|
||
To start the EchoServer use `sbt run`. | ||
|
||
## Important Note | ||
Until further notice you will need to `sbt publishLocal` the JMS4S library from the `combined-features` branch of this repository: https://github.com/rwalpole/jms4s |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
ThisBuild / scalaVersion := "2.13.8" | ||
ThisBuild / version := "0.1.0-SNAPSHOT" | ||
ThisBuild / organization := "uk.gov.nationalarchives" | ||
ThisBuild / organizationName := "The National Archives" | ||
ThisBuild / startYear := Some(2023) | ||
ThisBuild / licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT")) | ||
ThisBuild / description := "JMS4S Request-Reply Stub" | ||
|
||
lazy val root = (project in file(".")) | ||
.enablePlugins(AutomateHeaderPlugin) | ||
.settings( | ||
name := "jms4s-request-reply-stub", | ||
libraryDependencies ++= Seq( | ||
"org.typelevel" %% "cats-effect" % "3.4.4", | ||
"org.typelevel" %% "cats-core" % "2.9.0", | ||
"org.typelevel" %% "cats-effect-kernel" % "3.4.4", | ||
"org.typelevel" %% "log4cats-core" % "2.5.0", | ||
"org.typelevel" %% "log4cats-slf4j" % "2.5.0", | ||
"dev.fpinbo" %% "jms4s-active-mq-artemis" % "0.0.1-350e4fd-SNAPSHOT", | ||
"dev.fpinbo" %% "jms4s-simple-queue-service" % "0.0.1-350e4fd-SNAPSHOT", | ||
"org.slf4j" % "slf4j-simple" % "2.0.6" % Runtime | ||
), | ||
headerLicense := Some(HeaderLicense.MIT("2023", "The National Archives")), | ||
|
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# the include should be done only once, at the beginning of the custom configuration file | ||
include classpath("application.conf") | ||
|
||
queues { | ||
request-general { } | ||
omega-editorial-web-application-instance-1 { } | ||
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. Why |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: "3.7" | ||
services: | ||
elasticmq-native: | ||
container_name: elasticmq-container | ||
ports: | ||
- 9324:9324 | ||
- 9325:9325 | ||
volumes: | ||
- type: bind | ||
source: ./custom.conf | ||
target: /opt/elasticmq.conf | ||
image: softwaremill/elasticmq-native |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import sbt._ | ||
|
||
object Dependencies { | ||
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.2.11" | ||
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. Is file used at all? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.8.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.9.0") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (c) 2023 The National Archives | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package uk.gov.nationalarchives.omega.jms | ||
|
||
import cats.effect._ | ||
import jms4s.JmsAcknowledgerConsumer.AckAction | ||
import jms4s.JmsClient | ||
import jms4s.config.QueueName | ||
import jms4s.sqs.simpleQueueService | ||
import jms4s.sqs.simpleQueueService._ | ||
import org.typelevel.log4cats.SelfAwareStructuredLogger | ||
import org.typelevel.log4cats.slf4j.Slf4jFactory | ||
|
||
import scala.concurrent.duration.DurationInt | ||
|
||
/** | ||
* Just a simple JMS echo server that received a request returns a | ||
* reply with a correlationId set to the messageId of the request message. | ||
* | ||
* Follows the "JMS Request/Reply Example" pattern set out | ||
* in the Enterprise Integration Patterns book, | ||
* see https://www.enterpriseintegrationpatterns.com/RequestReplyJmsExample.html. | ||
* | ||
* Can be used for testing. | ||
* | ||
* @author <a href="mailto:[email protected]">Adam Retter</a> | ||
*/ | ||
object EchoServer extends IOApp { | ||
|
||
private val logging = Slf4jFactory[IO] | ||
private implicit val logger: SelfAwareStructuredLogger[IO] = logging.getLogger | ||
private val clientId = "echo_server_1" | ||
private val requestQueue = QueueName("request-general") | ||
private val replyQueue = QueueName("omega-editorial-web-application-instance-1") //TODO(AR) note this is for the editorial web application | ||
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. Perhaps it's clear enough without the comment? |
||
private val consumerConcurrencyLevel = 1 //0 | ||
|
||
private val jmsClient: Resource[IO, JmsClient[IO]] = simpleQueueService.makeJmsClient[IO]( | ||
Config( | ||
endpoint = Endpoint(Some(DirectAddress(HTTP, "localhost", Some(9324))),"elasticmq"), | ||
credentials = Some(Credentials("x","x")), | ||
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. Could these creds be anything? |
||
clientId = ClientId(clientId), | ||
None | ||
) | ||
) | ||
|
||
override def run(args: List[String]): IO[ExitCode] = { | ||
|
||
val consumerRes = for { | ||
_ <- Resource.liftK(IO.println("Starting EchoServer...")) | ||
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. Not 100% sure how cats effects IO class works, but do we want to use the logger here instead of println? |
||
client <- jmsClient | ||
consumer <- client.createAcknowledgerConsumer(requestQueue, concurrencyLevel = consumerConcurrencyLevel, pollingInterval = 50.millis) | ||
} yield consumer | ||
|
||
consumerRes.use(_.handle { (jmsMessage, mf) => | ||
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. Perhaps rename |
||
for { | ||
requestText <- jmsMessage.asTextF[IO] | ||
_ <- IO.println(s"Echo Server received message: $requestText") | ||
responseText <- IO.pure(s"Echo Server: $requestText") | ||
responseMessage <- mf.makeTextMessage(responseText) | ||
// PERFORM THE ACTUAL SERVICE HERE | ||
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. Is this note still needed ( |
||
// NOTE(AR) set correlationId on response message to the request message id | ||
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. Perhaps it's clear enough without the comment? |
||
requestMessageId = jmsMessage.getJMSMessageId.get | ||
_ = responseMessage.setJMSCorrelationId(requestMessageId) | ||
_ <- IO.println(s"Echo Server sending response message: $responseText with correlationId: $requestMessageId") | ||
} yield AckAction.send(responseMessage, replyQueue) | ||
}).as(ExitCode.Success) | ||
} | ||
|
||
} |
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.
Could we add some instructions for demonstrating this, using the restful API?
See this comment.