PHPackages                             ozean12/googlepubsub - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ozean12/googlepubsub

ActiveLibrary[API Development](/categories/api)

ozean12/googlepubsub
====================

A Symfony 2/3 integration with Google Cloud PubSub

1.0(6y ago)13.0kPHPPHP ^7.0|^5.0CI failing

Since Jan 5Pushed 6y ago28 watchersCompare

[ Source](https://github.com/ozean12/GooglePubSubBundle)[ Packagist](https://packagist.org/packages/ozean12/googlepubsub)[ RSS](/packages/ozean12-googlepubsub/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (3)Versions (6)Used By (0)

[![Build Status](https://camo.githubusercontent.com/b942e552e3a21946b9628d8c16578418c76bb2bd3b56b08fea90affc397ef330/68747470733a2f2f7472617669732d63692e6f72672f6f7a65616e31322f476f6f676c6550756253756242756e646c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ozean12/GooglePubSubBundle)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/020a5b72586b9661bed044b1917a2d8f0e8ff2909120bc14d9f6bc7ce350ee0a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f7a65616e31322f476f6f676c6550756253756242756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ozean12/GooglePubSubBundle/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/744cf5910dc730bc378fc15847f92857bdc6a70a5998d557c48ff49650d48f4f/68747470733a2f2f706f7365722e707567782e6f72672f6f7a65616e31322f676f6f676c657075627375622f762f737461626c652e706e67)](https://packagist.org/packages/ozean12/googlepubsub)[![Total Downloads](https://camo.githubusercontent.com/c578a1511f6828dd9532fd0ca56653345f40ef75ab658c5cf22a7bb799c29736/68747470733a2f2f706f7365722e707567782e6f72672f6f7a65616e31322f676f6f676c657075627375622f646f776e6c6f6164732e706e67)](https://packagist.org/packages/ozean12/googlepubsub)

Ozean12GooglePubSubBundle
=========================

[](#ozean12googlepubsubbundle)

A Symfony 2 / Symfony 3 bundle which integrates [Google Cloud Pub Sub](https://cloud.google.com/pubsub/docs/overview) with your application.

Installation
------------

[](#installation)

##### 1. Require the bundle:

[](#1-require-the-bundle)

```
composer require ozean12/googlepubsub
```

##### 2. Set it up:

[](#2-set-it-up)

```
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new JMS\SerializerBundle\JMSSerializerBundle(), // if not already enabled
        new Ozean12\WebTranslateItBundle\Ozean12WebTranslateItBundle(),
    ];

    // ...
}
```

```
# app/config/config.yml

ozean12_google_pub_sub:
  # your Google Cloud Project ID
  project_id: "%google_pub_sub_project_id%"

  # path to your Google Cloud Application Credentials file
  key_file_path: "%google_pub_sub_key_file_path%"

  # add this if you want to use logger (see Using Logger section for more info)
  logger_channel: pub_sub

  # list of PubSub topics (See Publishing section for more info)
  topics:
    - my_topic

  # list of Push subscriptions in format (subscription_name: service_name) (see Subscribing to Push messages section for more info)
  push_subscriptions:
    my_push_subscription: my_bundle.my_firts_push.subscriber
```

Usage
-----

[](#usage)

### 1. Publishing messages

[](#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:

```
$message = new MyTopicMessage();
$publisher = $this->container->get('ozean12_google_pubsub.publisher.my_topic');
$result = $publisher->publish($message);
```

`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

[](#2-subscribing-to-push-messages)

When using the [Push subscription](https://cloud.google.com/pubsub/docs/subscriber#overview-of-subscriptions), 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](http://symfony.com/doc/current/bundles/FOSRestBundle/index.html):

```
// GoogleCloudController.php

use Ozean12\GooglePubSubBundle\DTO\PushMessageRequestDTO;

/**
 * Class GoogleCloudController
 *
 * @Version("v1")
 * @Route("/google-cloud/")
 */
class GoogleCloudController extends FOSRestController
{
    /**
     * @ApiDoc(
     *   resource = true,
     *   description = "Receive a new PubSub message and process it",
     *   statusCodes = {
     *     204 = "Returned when successful",
     *     403 = "Returned when access denied"
     *   }
     * )
     *
     * @ParamConverter("message", converter="fos_rest.request_body")
     *
     * @Route("pub-sub")
     * @Method({"POST"})
     * @View()
     *
     * @param PushMessageRequestDTO $message
     * @return mixed
     */
    public function pubSub(PushMessageRequestDTO $message)
    {
        $this->get('ozean12_google_pubsub.push_subscriber_manager.service')->processMessage($message);
    }
}
```

By using the `@ParamConverter` annotation Symfony will automatically convert the request to `PushMessageRequestDTO`

`PushMessageRequestDTO` has two properties:

- `message`: instance of `PushMessageDTO`. For all the fields refer to [Push request body](https://cloud.google.com/pubsub/docs/subscriber#receive)
- `subscription`: 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:

```
// MyPushSubscriber.php

use Ozean12\GooglePubSubBundle\DTO\PushMessageDTO;
use Ozean12\GooglePubSubBundle\Service\Subscriber\PushSubscriberInterface;

/**
 * Class MyPushSubscriber
 */
class MyPushSubscriber implements PushSubscriberInterface
{
    /**
     * {@inheritdoc}
     */
    public function process(PushMessageDTO $message)
    {
        /** @var SendTransactionalEmailDataDTO $emailDTO */
        $data = base64_decode($message->getData())

        // process your data here
    }
}
```

### 3. Using Logger

[](#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:

```
monolog:
  handlers:
    # ...
    pub_sub:
      type:  stream
      path:  "%kernel.logs_dir%/pub_sub_%kernel.environment%.log"
      level: info
      channels: [pub_sub]
  channels:
    # ...
    - pub_sub

ozean12_google_pub_sub:
  # ...
  logger_channel: pub_sub
```

This will produce following log entries:

```
[2016-12-23 17:51:42] pub_sub.INFO: New topic my_topic created {"topic":"my_topic"} []
[2016-12-23 17:57:01] pub_sub.INFO: Message(s) 123456789 submitted to topic my_topic {"messages":"123456789","topic":"my_topic"} []
[2017-01-04 15:57:32] pub_sub.INFO: Received message : my_first_subscription[123456789]; Processed with MyBundle\Service\GooglePubSub\Subscriber\MyFirstSubscriber subscriber {"message":"123456789","subscription":"my_first_subscription","subscriberClass":"MyBundle\\Service\\GooglePubSub\\Subscriber\\MyFirstSubscriber"} []

```

Credits
-------

[](#credits)

[Ozean12](http://ozean12.com)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~926 days

Total

2

Last Release

2484d ago

Major Versions

0.1 → 1.02019-07-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ac44ee885055e160f28832ec719fb1a6bfd0336dfee202592b9b45116992ad7?d=identicon)[ardemchenkov](/maintainers/ardemchenkov)

---

Top Contributors

[![alahtarin](https://avatars.githubusercontent.com/u/4181814?v=4)](https://github.com/alahtarin "alahtarin (9 commits)")[![AhmedSamy](https://avatars.githubusercontent.com/u/2566979?v=4)](https://github.com/AhmedSamy "AhmedSamy (3 commits)")[![schneekatze](https://avatars.githubusercontent.com/u/10722292?v=4)](https://github.com/schneekatze "schneekatze (2 commits)")[![Ardem](https://avatars.githubusercontent.com/u/346908?v=4)](https://github.com/Ardem "Ardem (1 commits)")

---

Tags

pub-sushared-libsymfonysymfony-bundle

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ozean12-googlepubsub/health.svg)

```
[![Health](https://phpackages.com/badges/ozean12-googlepubsub/health.svg)](https://phpackages.com/packages/ozean12-googlepubsub)
```

###  Alternatives

[voryx/restgeneratorbundle

REST API Generator for Symfony 2

178141.7k1](/packages/voryx-restgeneratorbundle)[fsc/hateoas-bundle

96215.4k1](/packages/fsc-hateoas-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
