ufo-tech / rpc-mercure-transport
Mercure transport layer for JSON-RPC event broadcasting between services.
Installs: 72
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:component
pkg:composer/ufo-tech/rpc-mercure-transport
Requires
- php: ^8.3
- symfony/event-dispatcher: ^7.2
- symfony/mercure-bundle: ^0.3.7
- symfony/messenger: ^7.2
- ufo-tech/json-rpc-bundle: ^9.1
Requires (Dev)
- phpunit/phpunit: ^11.0
- symfony/framework-bundle: ^7.2
- symfony/http-kernel: ^7.2
Suggests
- symfony/http-client: To publish events asynchronously via Mercure
README
🚀 RpcMercureTransport
Mercure Transport Layer for JSON-RPC-BUNDLE
Adds support for cross-domain events between services via Mercure Hub.
🧬 Idea
This extension for JSON-RPC-BUNDLE allows publishing events from the RPC server to the Mercure Hub and receiving them by other services that are subscribed to the corresponding topics.
This enables building asynchronous event-driven interaction between microservices, without the need for RabbitMQ or other brokers.
Environment Requirements
⚙️ Installation
composer require ufo-tech/rpc-mercure-transport
🔧 Configuration
config/packages/ufo_json_rpc.yaml:
ufo_json_rpc: # ... transports: async: # ... - type: 'mercure' config: name: 'rpc_socket' dsn: '%env(resolve:MERCURE_PUBLIC_URL)%' topics_prefix: 'rpc.event.'
🚀 Send a message
If an RpcSocketRequestEvent event is dispatched in the EventDispatcher, the service automatically publishes it to the Mercure Hub.
The library includes syntactic sugar Ufo\RpcMercure\Services\RpcSocketTransport::fireEvent
use Ufo\RpcMercure\Services\RpcSocketTransport; class SomeService { public function __construct( protected RpcSocketTransport $rpcSocketTransport, ) {} public function someMethod(): void { $this->rpcSocketTransport->fireEvent( eventName: 'event.test', eventData: [ 'someKey' => 'some value', ] ), ); } }
→ on the Mercure side, this event will be sent to the topic [topics_prefix].request.
Other services in your SOA subscribed to this topic will instantly receive messages via SSE.
📡 Example of subscribing to requests
php bin/console ufo:rpc:socket:consume --topic=request -v
Connect to socket: request
2025-11-19 16:09:30:
>>> {"id":"691debba4a97b","method":"event.test","jsonrpc":"2.0","params":{"$rpc":{"timeout":10,"rayId":"691debba4a97b"}}}
Service "event.test" is not found on RPC Service Map
====================================================================================================
2025-11-19 16:09:30:
>>> {"id":"691debba83412","method":"ping","jsonrpc":"2.0","params":{"$rpc":{"timeout":10,"rayId":"691debba83412"}}}
<<< {"id":"691debba83412","result":"PONG","jsonrpc":"2.0"}
====================================================================================================
2025-11-19 16:09:30:
>>> {"id":"691debba8ef62","method":"Messenger.send","jsonrpc":"2.0","params":{"$rpc":{"timeout":10,"rayId":"691debba8ef62"}}}
Required parameter "message" not passed
📡 Example of subscribing to responses
php bin/console ufo:rpc:socket:consume --topic=response -v
Connect to socket: response
2025-11-19 16:09:30:
{"id":"691debba83412","result":"PONG","jsonrpc":"2.0"}
====================================================================================================
2025-11-19 16:09:30:
{"id":"691debba8ef62","error":"Required parameter "message" not passed","jsonrpc":"2.0"}
🧠 Main idea
- each RPC service has its own events (domain events)
rpc-mercure-transportbroadcasts them to the Mercure Hub- other services can react to them without direct dependency, just by implementing a method named after the event
🦠 License
MIT © UFO-Tech