Download the PHP package ozean12/googlepubsub without Composer
On this page you can find all versions of the php package ozean12/googlepubsub. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ozean12/googlepubsub
More information about ozean12/googlepubsub
Files in ozean12/googlepubsub
Package googlepubsub
Short Description A Symfony 2/3 integration with Google Cloud PubSub
License
Informations about the package googlepubsub
Ozean12GooglePubSubBundle
A Symfony 2 / Symfony 3 bundle which integrates Google Cloud Pub Sub with your application.
Installation
1. Require the bundle:
2. Set it up:
Usage
1. Publishing messages
In order to publish the message to PubSub, you need to define the topic first, as described in previous section. Once topic is defined, it can be accessed within the Publisher service:
MyTopicMessage
is a simple class which implements the Ozean12\GooglePubSubBundle\DTO\MessageDataDTOInterface
interface and holds the data which needs to be included in message.
publish
method also accepts attributes
array as a second argument.
If topic does not exist, it will be created automatically.
Result of the call will be an instance of Ozean12\GooglePubSubBundle\DTO\PublishMessageResultDTO
which will contain the ids of created messages.
2. Subscribing to Push messages
When using the Push subscription, you need to create the endpoint which will receive the message from Google Pub/Sub and then pass it to PushSubscriberManager
. This topic is outside the scope of the bundle. An example of this setup using the FOS REST Bundle:
By using the @ParamConverter
annotation Symfony will automatically convert the request to PushMessageRequestDTO
PushMessageRequestDTO
has two properties:
message
: instance ofPushMessageDTO
. For all the fields refer to Push request bodysubscription
: a string with the name of Pub/Sub subscription
The PushSubscriberManager->processMessage()
method will iterate over all registered subscribers and run the one with the name equal to the subscription property of the message. Example of subscriber:
3. Using Logger
If you want to log the interaction with Google services, setup the logger_channel
option with the channel you want to use. Ex:
This will produce following log entries: