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

add agent middleware #97

Closed
3 tasks
TimoGlastra opened this issue Sep 6, 2020 · 4 comments · Fixed by #1894
Closed
3 tasks

add agent middleware #97

TimoGlastra opened this issue Sep 6, 2020 · 4 comments · Fixed by #1894

Comments

@TimoGlastra
Copy link
Contributor

As a developer I sometimes want to apply custom logic for all incoming messages. We already have handlers that allow to implement logic for a custom message type. I think it would be beneficial to introduce the concept of middleware into aries-framework-javascript.

aries-framework-dotnet also implements the concept of middleware which we can take as an example

Checklist

  • create AgentMiddleware interface
  • call middleware before/after passing to handler (see question below)
    • I think Dispatcher would be the best place to call middleware
  • add function to register middleware to Agent (likeregisterHandlers)
    • one function to register them all, or function that can be called multiple times?

Questions

  • When should middleware be called?
    • Before passing to handler / after passing to handler / both?
    • .NET runs the middleware after passing a message to the handler.

Use cases

Probably a lot more, but this are two I can think of at the moment.

@ajile-in
Copy link
Contributor

ajile-in commented Sep 8, 2020

This would be a nice enhancement @TimoGlastra .
However, in my opinion, the AFJ library should define the AgentMiddleware abstraction / interfaces, and NOT the concrete implementations of the Middleware. Those are normally provided in the runtime like Node.js Web framework-level like Express, Oak, etc.

AF .NET also does the same way I described.
For example the interface is defined here in the Framework abstraction:

.. and the implementation is in

Happy to discuss if there are other ideas, or if I am missing something here..

@gnarula
Copy link
Contributor

gnarula commented Sep 11, 2020

I'd suggest having the middleware execute both, before the call to the handler and after the result of the handler is handled (i.e. outgoing message is sent).

The latter would specially be useful for scenarios where we need to be certain that the other party has received the message.
Example: In ConnectionService, we mark the state as COMPLETE before the ack message is sent. Ideally we'd want that to be done after the message is send successfully.

@ajile-in
Copy link
Contributor

We discussed & agreed in today's meeting that the middleware implementation will be runtime-agnostic. So that it may be consumed in Node.js Express, Deno or React-Native.

@bilal12367
Copy link

bilal12367 commented Mar 29, 2023

@TimoGlastra @ajile-in @gnarula Sir do we have any library currently available in AFJ, from which we can apply custom logic to all incoming messages like the IAgentMiddleware in .NET ?

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

Successfully merging a pull request may close this issue.

4 participants