ecotone-dev
ecotone-dev copied to clipboard
Combined channel for outbox: DB -> distributed publisher
Description
Sending a command to another microservice should also be guaranteed through the outbox pattern. It is currently not possible to combine these channels through a combined channel. Currently there are 3 stages: db consumer -> async (internal consumer) -> publisher (new message to distributed bus exchange).
Example Service configuration for async outbox
#[ServiceContext]
public function enableRabbitMq(): AmqpBackedMessageChannelBuilder
{
return AmqpBackedMessageChannelBuilder::create('internal');
}
#[ServiceContext]
public function databaseChannel(): DbalBackedMessageChannelBuilder
{
return DbalBackedMessageChannelBuilder::create('db');
}
#[ServiceContext]
public function combinedMessageChannel(): CombinedMessageChannel
{
return CombinedMessageChannel::create(
'outbox',
['db', 'internal'],
);
}
Distributed bus publisher:
#[EventHandler(endpointId: 'order.changed')]
#[Asynchronous('outbox')]
public function changeBillingDetails(OrderChanged $event, DistributedBus $distributedBus): void
{
$distributedBus->sendCommand(
'billing',
'billing.changeDetails',
'["personId":"123","billingDetails":"01111"]',
'application/json',
);
}
Is it possible to make sending a command to a db channel with automatic sending to the distributed channel (combined channel between db and distributed), skipping sending OrderChanged to async internal channel? For example:
$distributedBus->sendCommand(
'billing_outbox', // combined channel db -> distributed publisher channel to billing service using Ecotone service configuration
'billing.changeDetails',
'["personId":"123","billingDetails":"01111"]',
'application/json',
);