We could create a guide for PubSub. In your app. I will change:
@Get("/publish")
@Status(HttpStatus.ACCEPTED)
void publishMsg() {
Person person = new Person("nirav", 44);
publisher.sendMessage(person);
}
don't return a string but just a Http status code. Since it causes side effects (a message being published) I will a Post instead of a GET.
Instead of printly I will use a logger:
private static final Logger LOG = LoggerFactory.getLogger(MyListener.class);
Jeremy Grelle | Jeremy Grelle | 12:24 PM (1 minute ago)
-- | -- | --
Jeremy Grelle
Jeremy Grelle
12:24 PM (1 minute ago)
to me
Nirav,
For setting up the PubSub emulator to work with Micronaut Test Resources, see the first link in the below email.
One thing I point out below but don't link to is that you also have to add the Test Resources Gradle plugin to the build - nothing special there, just done as indicated in the Test Resources docs.
---------- Forwarded message ---------
From: Jeremy Grelle <[grellej@objectcomputing.com](mailto:grellej@objectcomputing.com)>
Date: Thu, Sep 22, 2022 at 1:06 PM
Subject: Integration Service PubSub
To: Jesse Elliott <[elliottj@objectcomputing.com](mailto:elliottj@objectcomputing.com)>, James Kirk <[kirkj@objectcomputing.com](mailto:kirkj@objectcomputing.com)>
Hey guys,
I've gotten our initial PubSub code merged into our main git branch, so wanted to give you a quick walkthrough as promised. This code shows publishing to PubSub topics, as it is for messages that we are sending to the ARMM services. The schema being used is a different one from what you'll be using, but the code would otherwise be quite similar.
We are using Micronaut Test Resources to automatically pull in and set up a Docker image of the GCP PubSub emulator for local development. You can see the specifics of that configuration here:
https://github.com/objectcomputing/hem-integration-services/blob/98decedbf56d192ff0109f89f0281da163547028/integration-orchestrator/src/main/resources/application.yml#L13-L27
It requires pulling in the Test Resources Gradle plugin and the Micronaut GCP PubSub module (io.micronaut.gcp:micronaut-gcp-pubsub) in your build.
You'll see it's using a publicly available image of the emulator that has some extra features such as being able to set up the PubSub topics via an environment variable.
Our Micronaut @PubSubClient is here:
https://github.com/objectcomputing/hem-integration-services/blob/main/integration-orchestrator/src/main/java/com/objectcomputing/hem/integration/armm/ArmmMessageChannels.java
We map our internal domain objects to the generated protobuf builder class (in this case from armm.proto) here:
https://github.com/objectcomputing/hem-integration-services/blob/main/integration-orchestrator/src/main/java/com/objectcomputing/hem/integration/armm/ArmmProtobufMapper.java
All of this is being driven from this service:
https://github.com/objectcomputing/hem-integration-services/blob/98decedbf56d192ff0109f89f0281da163547028/integration-orchestrator/src/main/java/com/objectcomputing/hem/integration/orchestrator/TokenPublisherService.java#L82-L86
The protobuf schema that we would like you to use is here:
https://github.com/objectcomputing/hem-integration-services/blob/main/message-schemas/src/main/proto/grpc/marketplace.proto
You can either run the protoc compiler against the schema yourself to generate the necessary builder classes, or clone our git repo and just grab the .jar file that is output from building the message-schemas subproject. In the near future, we'll start publishing that .jar file to a shared artifact repository so you can just pull it in as a Gradle dependency.
Feel free to send PRs our way to change the marketplace.proto schema if needed.
Let me know if you have any further questions.
--
Jeremy Grelle
Senior Software Engineer
tel (314) 579-0066
mobile (678) 677-2149
[objectcomputing.com](https://objectcomputing.com/)
YOUR OUTCOMES ENGINEEREDâ„¢
--
Jeremy Grelle
Senior Software Engineer
tel (314) 579-0066
mobile (678) 677-2149
suggestions from sergio
@Get("/publish") @Status(HttpStatus.ACCEPTED) void publishMsg() { Person person = new Person("nirav", 44); publisher.sendMessage(person); }
private static final Logger LOG = LoggerFactory.getLogger(MyListener.class);
@Subscription("myListener") // public void onMessage(Person person) { LOG.info("received message: " + person); }```