Skip to content

feat(async): Implement request-reply for kafka - #2031

Merged
lbroudoux merged 5 commits into
microcks:masterfrom
adamhicks:adam-kafkareply
Apr 28, 2026
Merged

lbroudoux merged 5 commits into
microcks:masterfrom
adamhicks:adam-kafkareply

Conversation

@adamhicks

Copy link
Copy Markdown
Contributor

Description

  • Implement a request reply handler that can monitor (kafka) topics for messages to reply to
  • Implement the request reply manager that can create monitors for operations (from the definitions streamed from the microcks API)
  • Implement testcontainers test for a request-reply interaction
  • Implement a message matcher based on body content, wasn't able to use Dispatch Criteria (open to discussion)

Related issue(s)

See #1916

@adamhicks
adamhicks requested review from lbroudoux and yada as code owners April 8, 2026 08:54
@adamhicks

Copy link
Copy Markdown
Contributor Author
$ mvn test
...
[INFO] Reactor Summary for Microcks 1.14.0-SNAPSHOT:
[INFO] 
[INFO] Microcks ........................................... SUCCESS [  0.420 s]
[INFO] Microcks Model ..................................... SUCCESS [  0.801 s]
[INFO] Microcks Util ...................................... SUCCESS [  2.517 s]
[INFO] Microcks EL ........................................ SUCCESS [  0.520 s]
[INFO] Microcks App ....................................... SUCCESS [ 54.300 s]
[INFO] Microcks Async Minion .............................. SUCCESS [  1.537 s]
[INFO] Microcks Distros ................................... SUCCESS [  0.006 s]
[INFO] Microcks Uber App .................................. SUCCESS [  0.075 s]
[INFO] Microcks Uber Async Minion ......................... SUCCESS [  0.094 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:00 min
[INFO] Finished at: 2026-04-08T09:56:02+01:00

@lbroudoux

Copy link
Copy Markdown
Member

This one could be merged "just-in-time" for 1.14.0. Cool 👍

import java.util.Iterator;

/**
* Compute dispatch criteria for async request-reply events.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried to define a JSON_BODY dispatch criteria when parsing the example but I think I struggled to get AND behaviour. I was trying to create "equals" criterion for each leaf of the example json. e.g. if the example was:

{
    "payment_request_id": 123,
    "user": {
          "id": 456
    }
}

I wanted the criteria to behave like (pseudo code):

if body.payment_request_id == 123 && body.user.id == 456 then
   return "example-1"
else
   return "unmatched"
end if


Operation signedupOperation = new Operation();
signedupOperation.setName("SUBSCRIBE user/signedup");
signedupOperation.addResourcePath(TOPIC_NAME);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this test actually broke in 9f78c58 where I changed getTopicName to use the channel name from the API doc (rather than a generated one)

@lbroudoux lbroudoux Apr 17, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, but channels/topic name override is super important to guarantee the isolation of mocks from different versions or even different APIs. We need to keep generated topic names with support of dynamic parts when using {} in the name.

@adamhicks

Copy link
Copy Markdown
Contributor Author

Tried to fix the sonar action as it was failing on getting coverage for an adjacent test to this PR.

Got a different error now that indicates auth with Sonar isn't set up or has expired

Error:  Error retrieving feature flags, using default analyzer behavior
Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator to check the permissions of the user the token belongs to

@adamhicks

Copy link
Copy Markdown
Contributor Author

This one could be merged "just-in-time" for 1.14.0. Cool 👍

I think this PR is ready for review, just making sure you're not waiting for me to do something more?

@lbroudoux

lbroudoux commented Apr 17, 2026 •

Copy link
Copy Markdown
Member

I think this PR is ready for review, just making sure you're not waiting for me to do something more?

No that's cool. It's just me: I'm super busy and slow at the moment. Apologies for that 🙏

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @adamhicks for pushing and thanks for your patience! There are some minor change requests but a major concern here is related to the dynamic topic resolution - it seems to be broken/removed now and I don't understand why you have to do so.


String topicName = producerManager.getTopicName(definition, eventMessage);
assertEquals("StreetlightsAPI-0.1.0-receiveLightMeasurement", topicName);
assertEquals("smartylighting.streetlights.1.0.event.lighting.measured", topicName);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not correct and breaks the existing conventions => we must ensure uniqueness of topic to avoid collisions between different versions or even different AsyncAPIs.

@adamhicks

Copy link
Copy Markdown
Contributor Author

Thanks @adamhicks for pushing and thanks for your patience! There are some minor change requests but a major concern here is related to the dynamic topic resolution - it seems to be broken/removed now and I don't understand why you have to do so.

The dynamic resolution (using parts of the example message) does need to come back.

The dynamic naming using service/operation/version info, I don't know how to make this compatible. How do clients currently find these topic names? E.g. if my application is expecting mocked events, does it need logic to be able to find microcks defined topic names? I'd expect the topic to be a fixed name defined in the spec, but I'm aware that I'm only really looking at my experience/use case here, so I'm keen to know how this is supposed to work 🙏

@lbroudoux

Copy link
Copy Markdown
Member

The dynamic resolution (using parts of the example message) does need to come back.

The dynamic naming using service/operation/version info, I don't know how to make this compatible. How do clients currently find these topic names? E.g. if my application is expecting mocked events, does it need logic to be able to find microcks defined topic names? I'd expect the topic to be a fixed name defined in the spec, but I'm aware that I'm only really looking at my experience/use case here, so I'm keen to know how this is supposed to work 🙏

Ok, let me try to explain.

Let's reason from an example: imagine the channel address in MyAsyncAPI, version 1.0 is defined as topic-{lightId} for operation SEND events.

To allow isolation of APIs and versions, Microcks will ignore the address from the spec and define the mock topic as being <service_name>-<service_version>-<operation_name>, so it should be MyAsyncAPI-1.0-events (as we remove the operation verb - here SEND). This is the generic case when using static destinations.

But here, the channel address is defined using a {} expression - which means it is dynamic and may change depending on event messages. In that case, Microcks detects this during the import and sets the dispatcher as URI_PARTS - then we use a slightly different naming convention, being now <service_name>-<service_version>-<dynamic_channel_name>. The lightId value will actually be extracted from mocked events and used to form the topic name.

So imagine, your event sample has a lightId being xyz, then the topic name computed by Microcks will now be MyAsyncAPI-1.0-topic-xyz.

How do clients currently find these topic names? E.g. if my application is expecting mocked events, does it need logic to be able to find microcks defined topic names?

The topic name (either static or dynamic) is rendered on the Microcks UI. So if you define multiple message samples in your AsyncAPI, you will have multiple thumbs in the Microcks UI with different topic names on each thumb.

Hope it makes it clearer. Let me know if it needs any further clarification.

@adamhicks

Copy link
Copy Markdown
Contributor Author

The topic name (either static or dynamic) is rendered on the Microcks UI. So if you define multiple message samples in your AsyncAPI, you will have multiple thumbs in the Microcks UI with different topic names on each thumb.

I'm coming at this from the perspective of an application that is expecting to receive events and do something with them. So it needs to know where to listen for these events. Would the expected workflow be for the user to use the Microcks UI to get the topic name and then configure there application with something like:

HELLO_BLOG_EVENTS_TOPIC_NAME= MyAsyncAPI-1.0-topic-xyz

?

If so, I think I get it :)

@lbroudoux

Copy link
Copy Markdown
Member

Yes, that's it. Maybe my example with {lightId} is not that great because it would lead to a lot of topics... Common use cases are topics per type/category or per grouping criteria. But you get the point! Thanks for the new commit, I'll review on tomorrow morning.

feat(async): restore isolated and dynamic topics

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks all good to me!

@lbroudoux
lbroudoux merged commit 9e53710 into microcks:master Apr 28, 2026
8 of 9 checks passed
lbroudoux added a commit that referenced this pull request Apr 29, 2026
* feat(async): Implement request-reply for kafka

Signed-off-by: Adam Hicks <[email protected]>

* fix: Try to fix the sonar cloud analysis

Signed-off-by: Adam Hicks <[email protected]>

* fix: File metadata and field case

Signed-off-by: Adam Hicks <[email protected]>

* feat(async): restore isolated and dynamic topics
Signed-off-by: Laurent Broudoux <[email protected]>

---------

Signed-off-by: Adam Hicks <[email protected]>
Co-authored-by: Laurent Broudoux <[email protected]>
(cherry picked from commit 9e53710)
sudheerr937-ai pushed a commit to sudheerr937-ai/microcks that referenced this pull request Apr 30, 2026
* feat(async): Implement request-reply for kafka

Signed-off-by: Adam Hicks <[email protected]>

* fix: Try to fix the sonar cloud analysis

Signed-off-by: Adam Hicks <[email protected]>

* fix: File metadata and field case

Signed-off-by: Adam Hicks <[email protected]>

* feat(async): restore isolated and dynamic topics
Signed-off-by: Laurent Broudoux <[email protected]>

---------

Signed-off-by: Adam Hicks <[email protected]>
Co-authored-by: Laurent Broudoux <[email protected]>
Signed-off-by: sudheerr937-ai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants