MqService
extends MqServiceBase
in package
Table of Contents
Properties
- $channel : AMQPChannel|null
- $connection : AMQPConnection|null
- $eventHandlers : array<string|int, mixed>
- $exchange : AmqpExchange|null
- $exchangeName : string
- $host : string
- $password : string
- $port : int
- $queueName : string|null
- $requeueUnhandled : bool
- $user : string
- $vhost : string
Methods
- __construct() : mixed
- Create a new instance of the MqService class.
- __destruct() : mixed
- Destructor to ensure connections are properly closed
- closeConnection() : void
- Close the AMQP connection and channel, and therefore remove all subscriptions.
- openConnection() : AMQPConnection
- Get the AMQP connection instance. If it does not exist, it will be created.
- publish() : void
- Publish a message to the service's queue, including the event name in the headers.
- send_cockpit_addRegistration() : void
- Send the cockpit.addRegistration event.
- send_customer_created() : void
- Send the customer.created event.
- send_customer_delete() : void
- Send the customer.delete event.
- send_customer_merge() : void
- Send the customer.merge event.
- send_email_button() : void
- Send the email.button event.
- send_email_generic() : void
- Send the email.generic event.
- startConsuming() : void
- Start consuming messages and routing them to registered handlers.
- subscribe() : void
- Register a handler for a specific event type.
- subscribe_cockpit_addRegistration() : void
- Subscribe to the cockpit.addRegistration event.
- subscribe_customer_created() : void
- Subscribe to the customer.created event.
- subscribe_customer_delete() : void
- Subscribe to the customer.delete event.
- subscribe_customer_merge() : void
- Subscribe to the customer.merge event.
- subscribe_email_button() : void
- Subscribe to the email.button event.
- subscribe_email_generic() : void
- Subscribe to the email.generic event.
- getChannel() : AMQPChannel
- Get the AMQP channel. If it does not exist, it will be created along with the queue.
- handleMessage() : void
- Handle an incoming message by routing it to the appropriate event handler.
Properties
$channel
private
AMQPChannel|null
$channel
= null
$connection
private
AMQPConnection|null
$connection
= null
$eventHandlers
private
array<string|int, mixed>
$eventHandlers
= []
$exchange
private
AmqpExchange|null
$exchange
= null
$exchangeName read-only
private
string
$exchangeName
= 'general'
$host read-only
private
string
$host
= 'localhost'
$password read-only
private
string
$password
= 'guest'
$port read-only
private
int
$port
= 5672
$queueName read-only
private
string|null
$queueName
= null
$requeueUnhandled read-only
private
bool
$requeueUnhandled
= false
$user read-only
private
string
$user
= 'guest'
$vhost read-only
private
string
$vhost
= '/'
Methods
__construct()
Create a new instance of the MqService class.
public
__construct([string $host = 'localhost' ][, int $port = 5672 ][, string $user = 'guest' ][, string $password = 'guest' ][, string $queueName = null ][, bool $requeueUnhandled = false ][, string $vhost = '/' ][, string $exchangeName = 'general' ]) : mixed
It will automatically connect to the AMQP server as soon as a method is called, and disconnect when the object is destroyed or the closeConnection method is called. If you just want to send a message, you still have to call the closeConnection method.
Parameters
- $host : string = 'localhost'
-
The AMQP server hostname
- $port : int = 5672
-
The AMQP server port
- $user : string = 'guest'
-
The AMQP server username
- $password : string = 'guest'
-
The AMQP server password
- $queueName : string = null
-
The queue name for the service, normally the service name
- $requeueUnhandled : bool = false
- $vhost : string = '/'
-
The AMQP server vhost
- $exchangeName : string = 'general'
-
The AMQP exchange name
__destruct()
Destructor to ensure connections are properly closed
public
__destruct() : mixed
closeConnection()
Close the AMQP connection and channel, and therefore remove all subscriptions.
public
closeConnection() : void
openConnection()
Get the AMQP connection instance. If it does not exist, it will be created.
public
openConnection() : AMQPConnection
Return values
AMQPConnection —The connection instance
publish()
Publish a message to the service's queue, including the event name in the headers.
public
publish(string $eventName, string $payload) : void
Parameters
- $eventName : string
-
The event name
- $payload : string
-
The message content
Tags
send_cockpit_addRegistration()
Send the cockpit.addRegistration event.
public
send_cockpit_addRegistration(CockpitAddRegistrationPayload $payload) : void
Parameters
- $payload : CockpitAddRegistrationPayload
-
The payload to send.
Tags
send_customer_created()
Send the customer.created event.
public
send_customer_created(CustomerCreatedEventPayload $payload) : void
Parameters
- $payload : CustomerCreatedEventPayload
-
The payload to send.
Tags
send_customer_delete()
Send the customer.delete event.
public
send_customer_delete(CustomerDeleteEventPayload $payload) : void
Parameters
- $payload : CustomerDeleteEventPayload
-
The payload to send.
Tags
send_customer_merge()
Send the customer.merge event.
public
send_customer_merge(MergeCustomerPayload $payload) : void
Parameters
- $payload : MergeCustomerPayload
-
The payload to send.
Tags
send_email_button()
Send the email.button event.
public
send_email_button(ButtonEmailEventPayload $payload) : void
Parameters
- $payload : ButtonEmailEventPayload
-
The payload to send.
Tags
send_email_generic()
Send the email.generic event.
public
send_email_generic(GenericEmailEventPayload $payload) : void
Parameters
- $payload : GenericEmailEventPayload
-
The payload to send.
Tags
startConsuming()
Start consuming messages and routing them to registered handlers.
public
startConsuming() : void
This method will block until the channel is closed.
Tags
subscribe()
Register a handler for a specific event type.
public
subscribe(string $eventName, callable $handler) : void
Parameters
- $eventName : string
-
The event name to subscribe to
- $handler : callable
-
Function to process received messages (function(string $payload))
Tags
subscribe_cockpit_addRegistration()
Subscribe to the cockpit.addRegistration event.
public
subscribe_cockpit_addRegistration(callable|CockpitAddRegistrationPayloadListener $callback) : void
Parameters
- $callback : callable|CockpitAddRegistrationPayloadListener
-
The callback or listener instance to call when the event is received.
subscribe_customer_created()
Subscribe to the customer.created event.
public
subscribe_customer_created(callable|CustomerCreatedEventPayloadListener $callback) : void
Parameters
- $callback : callable|CustomerCreatedEventPayloadListener
-
The callback or listener instance to call when the event is received.
subscribe_customer_delete()
Subscribe to the customer.delete event.
public
subscribe_customer_delete(callable|CustomerDeleteEventPayloadListener $callback) : void
Parameters
- $callback : callable|CustomerDeleteEventPayloadListener
-
The callback or listener instance to call when the event is received.
subscribe_customer_merge()
Subscribe to the customer.merge event.
public
subscribe_customer_merge(callable|MergeCustomerPayloadListener $callback) : void
Parameters
- $callback : callable|MergeCustomerPayloadListener
-
The callback or listener instance to call when the event is received.
subscribe_email_button()
Subscribe to the email.button event.
public
subscribe_email_button(callable|ButtonEmailEventPayloadListener $callback) : void
Parameters
- $callback : callable|ButtonEmailEventPayloadListener
-
The callback or listener instance to call when the event is received.
subscribe_email_generic()
Subscribe to the email.generic event.
public
subscribe_email_generic(callable|GenericEmailEventPayloadListener $callback) : void
Parameters
- $callback : callable|GenericEmailEventPayloadListener
-
The callback or listener instance to call when the event is received.
getChannel()
Get the AMQP channel. If it does not exist, it will be created along with the queue.
private
getChannel() : AMQPChannel
Return values
AMQPChannel —The channel instance
handleMessage()
Handle an incoming message by routing it to the appropriate event handler.
private
handleMessage(AMQPEnvelope $message, AMQPQueue $queue) : void
Parameters
- $message : AMQPEnvelope
-
The incoming AMQP message
- $queue : AMQPQueue