Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

PACT-709: First implementation of stub #1

wants to merge 3 commits into from

Conversation

rwalpole
Copy link
Contributor

No description provided.

@rwalpole rwalpole force-pushed the PACT-709 branch 2 times, most recently from bf995c4 to 92743cf Compare January 31, 2023 15:14
@rwalpole rwalpole requested a review from a user January 31, 2023 15:15
@ghost
Copy link

ghost commented Jan 31, 2023

I'm having a bit of trouble getting this to run, following the README.

Bringing up the containers is fine:

NAME                  IMAGE                           COMMAND                  SERVICE             CREATED             STATUS              PORTS
elasticmq-container   softwaremill/elasticmq-native   "/sbin/tini -- /opt/…"   elasticmq-native    2 minutes ago       Up 2 minutes        0.0.0.0:9324-9325->9324-9325/tcp

However:

sbt run
[info] welcome to sbt 1.8.2 (Homebrew Java 11.0.18)
[info] loading global plugins from /Users/tna/.sbt/1.0/plugins
[info] loading settings for project jms4s-request-reply-stub-build from plugins.sbt ...
[info] loading project definition from /Users/tna/work/jms4s-request-reply-stub/project
[info] loading settings for project root from build.sbt ...
[info] set current project to jms4s-request-reply-stub (in build file:/Users/tna/work/jms4s-request-reply-stub/)
[info] Updating 
[info] Resolved  dependencies
[warn] 
[warn]  Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading dev.fpinbo:jms4s-simple-queue-service_2.13:0.0.1-350e4fd-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /Users/tna/.ivy2/localdev.fpinbo/jms4s-simple-queue-service_2.13/0.0.1-350e4fd-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/dev/fpinbo/jms4s-simple-queue-service_2.13/0.0.1-350e4fd-SNAPSHOT/jms4s-simple-queue-service_2.13-0.0.1-350e4fd-SNAPSHOT.pom
[error] Error downloading dev.fpinbo:jms4s-active-mq-artemis_2.13:0.0.1-350e4fd-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /Users/tna/.ivy2/localdev.fpinbo/jms4s-active-mq-artemis_2.13/0.0.1-350e4fd-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/dev/fpinbo/jms4s-active-mq-artemis_2.13/0.0.1-350e4fd-SNAPSHOT/jms4s-active-mq-artemis_2.13-0.0.1-350e4fd-SNAPSHOT.pom
[error]         at lmcoursier.CoursierDependencyResolution.unresolvedWarningOrThrow(CoursierDependencyResolution.scala:344)
[error]         at lmcoursier.CoursierDependencyResolution.$anonfun$update$38(CoursierDependencyResolution.scala:313)
[error]         at scala.util.Either$LeftProjection.map(Either.scala:573)
[error]         at lmcoursier.CoursierDependencyResolution.update(CoursierDependencyResolution.scala:313)
[error]         at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:60)
[error]         at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:59)
[error]         at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:133)
[error]         at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:73)
[error]         at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$20(LibraryManagement.scala:146)
[error]         at scala.util.control.Exception$Catch.apply(Exception.scala:228)
[error]         at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:146)
[error]         at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:127)
[error]         at sbt.util.Tracked$.$anonfun$inputChangedW$1(Tracked.scala:219)
[error]         at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:160)
[error]         at sbt.Classpaths$.$anonfun$updateTask0$1(Defaults.scala:3687)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]         at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error]         at sbt.Execute.work(Execute.scala:291)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error]         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error]         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error]         at java.base/java.lang.Thread.run(Thread.java:829)
[error] (update) sbt.librarymanagement.ResolveException: Error downloading dev.fpinbo:jms4s-simple-queue-service_2.13:0.0.1-350e4fd-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /Users/tna/.ivy2/localdev.fpinbo/jms4s-simple-queue-service_2.13/0.0.1-350e4fd-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/dev/fpinbo/jms4s-simple-queue-service_2.13/0.0.1-350e4fd-SNAPSHOT/jms4s-simple-queue-service_2.13-0.0.1-350e4fd-SNAPSHOT.pom
[error] Error downloading dev.fpinbo:jms4s-active-mq-artemis_2.13:0.0.1-350e4fd-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /Users/tna/.ivy2/localdev.fpinbo/jms4s-active-mq-artemis_2.13/0.0.1-350e4fd-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/dev/fpinbo/jms4s-active-mq-artemis_2.13/0.0.1-350e4fd-SNAPSHOT/jms4s-active-mq-artemis_2.13-0.0.1-350e4fd-SNAPSHOT.pom
[error] Total time: 1 s, completed 31 Jan 2023, 16:33:03

Am I missing a step?

@rwalpole
Copy link
Contributor Author

@tna-erasmos until such a time as these two PRs fp-in-bo/jms4s#363 & fp-in-bo/jms4s#359 have been merged we will have to maintain a hybrid version which has both which I have created here . You will need to check out this combined-features branch and install it locally with sbt publishLocal. I did mention this in build.sbt but I didn't want to put it in the README as I hope this is only a temporary solution.

@ghost
Copy link

ghost commented Feb 1, 2023

@rwalpole, how about we put those instructions in the README, temporarily?

@rwalpole
Copy link
Contributor Author

rwalpole commented Feb 1, 2023

@tna-erasmos, sure, updated README.

@ghost
Copy link

ghost commented Feb 1, 2023

Some progress.

I built this branch of jms4s and published it locally:

/Users/tna/.ivy2/local/
└── dev.fpinbo
    ├── jms4s-active-mq-artemis_2.13
    │   └── 0.0.1-2d6d83c
    ├── jms4s-ibm-mq_2.13
    │   └── 0.0.1-2d6d83c
    ├── jms4s-simple-queue-service_2.13
    │   └── 0.0.1-2d6d83c
    └── jms4s_2.13
        └── 0.0.1-2d6d83c

However, sbt run still failed.

It was due to build.sbt referring to different versions:

"dev.fpinbo" %% "jms4s-active-mq-artemis" % "0.0.1-350e4fd-SNAPSHOT",
"dev.fpinbo" %% "jms4s-simple-queue-service" % "0.0.1-350e4fd-SNAPSHOT",

I changed this to:

"dev.fpinbo" %% "jms4s-active-mq-artemis" % "0.0.1-2d6d83c",
"dev.fpinbo" %% "jms4s-simple-queue-service" % "0.0.1-2d6d83c",

And it worked.

sbt run
[info] welcome to sbt 1.8.2 (Homebrew Java 11.0.18)
[info] loading global plugins from /Users/tna/.sbt/1.0/plugins
[info] loading settings for project jms4s-request-reply-stub-build from plugins.sbt ...
[info] loading project definition from /Users/tna/work/jms4s-request-reply-stub/project
[info] loading settings for project root from build.sbt ...
[info] set current project to jms4s-request-reply-stub (in build file:/Users/tna/work/jms4s-request-reply-stub/)
[info] running uk.gov.nationalarchives.omega.jms.EchoServer 
Starting EchoServer...
[io-compute-blocker-4] INFO uk.gov.nationalarchives.omega.jms.EchoServer - Opening context to MQ at Region: elasticmq DirectAddress(HTTP,localhost,Some(9324))...
[io-compute-blocker-4] INFO uk.gov.nationalarchives.omega.jms.EchoServer - Opened context com.amazon.sqs.javamessaging.SQSSession@608f5f86
[io-compute-blocker-4] INFO uk.gov.nationalarchives.omega.jms.EchoServer - Creating context
[io-compute-blocker-4] INFO uk.gov.nationalarchives.omega.jms.EchoServer - Context com.amazon.sqs.javamessaging.SQSSession@49f4130f successfully created
[io-compute-blocker-4] INFO uk.gov.nationalarchives.omega.jms.EchoServer - Creating consumer for destination QueueName(request-general)

And from the Elastic MQ console at http://localhost:9325/, I can see that there are two queues:

image

I'm guessing that the other queue is for responses.

Now I just need to figure out how to take it for a spin.

@ghost
Copy link

ghost commented Feb 1, 2023

I sorted it; see my QA here.

I'll start to review the code, itself.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, as-is.

Though I'd recommend adding more instructions.

# JMS4s Request-Reply Stub
Copy link

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.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's clear enough without the comment?

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")),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these creds be anything?

consumer <- client.createAcknowledgerConsumer(requestQueue, concurrencyLevel = consumerConcurrencyLevel, pollingInterval = 50.millis)
} yield consumer

consumerRes.use(_.handle { (jmsMessage, mf) =>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps rename mf to messageFactory?

_ <- IO.println(s"Echo Server received message: $requestText")
responseText <- IO.pure(s"Echo Server: $requestText")
responseMessage <- mf.makeTextMessage(responseText)
// PERFORM THE ACTUAL SERVICE HERE
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this note still needed (ACTUAL SERVICE)?

responseText <- IO.pure(s"Echo Server: $requestText")
responseMessage <- mf.makeTextMessage(responseText)
// PERFORM THE ACTUAL SERVICE HERE
// NOTE(AR) set correlationId on response message to the request message id
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's clear enough without the comment?


queues {
request-general { }
omega-editorial-web-application-instance-1 { }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why instance-1?

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, the lib version should be updated.

override def run(args: List[String]): IO[ExitCode] = {

val consumerRes = for {
_ <- Resource.liftK(IO.println("Starting EchoServer..."))
Copy link

Choose a reason for hiding this comment

The 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?

import sbt._

object Dependencies {
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.2.11"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is file used at all?
Also, are we going to be using scalatest or Munit?

@ghost
Copy link

ghost commented Feb 2, 2023

Now I'm wondering if we need this stub service at all.

I had expected that this would have been integrated into ctd-omega-editorial-frontend, as a stop gap until we get the real backend (API Services); and perhaps it could even be repurposed for integration testing.

I'll bring it up at standup.

@ghost
Copy link

ghost commented Feb 2, 2023

@rwalpole has explained that two attempts were already made to integrate the stub inside ctd-omega-editorial-frontend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants