2017 © Pedro Peláez
 

symfony-bundle bus

Message Bus Bundle uses for communication among microservices through message bus (by default is RabbitMQ)

image

garlic/bus

Message Bus Bundle uses for communication among microservices through message bus (by default is RabbitMQ)

  • Tuesday, January 30, 2018
  • by garlic
  • Repository
  • 0 Watchers
  • 3 Stars
  • 966 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 14 % Grown

The README.md

Garlic message bus

This bundle allow microservices communicate to each other with RabbitMQ transport by providing message bus., (*1)

For correct usage the Bundle must be installed on both ends of communication (current and target services), (*2)

Installation

Just a couple things are necessary for this bundle works., (*3)

Add garlic/bus bundle to your composer.json

composer require garlic/bus

Run processor as a Daemon (add configuration to your supervisor.conf)

[program:garlic_communication]
command=/var/www/bin/console --env=prod --no-debug enqueue:consume --setup-broker
process_name=%(program_name)s_%(process_num)02d
numprocs=4
autostart=true
autorestart=true
tartsecs=0
user=www-data
redirect_stderr=true

Now you can use Garlic Bus, (*4)

Optional: You can set timeout which will used to wait for response

Set variable REQUEST_TIMEOUT=30 where 30 is seconds, (*5)

Usage

Common way to use

If you want to get response from current service you have to use 'request' method, like explained below, (*6)

$data = $this->get('communicator') // Or you can call by class name. Example: $this->get(GarlicBus:class)
    ->request('targetServiceName') // Type of message. So far you can use ->request() or ->command() methods. Command provide mesage type that not need response. 
    ->post()                       // Set one of REST methods (post, put, delete). Bu default set GET 
    ->targetServiceAction(         // CamelCased route where slashes vere changed to upper letter by magic (example: getUser will changed to /get/user)
        array $path = [],          // Path parameters to query (example: ['user' => 1])
        array $query = [],         // Post or Get parameters to the query
        array $headers = []        // Additional headers
    );

or the same but using direct rout as a method parameter, (*7)

$data = $this->get('communicator')
    ->request('targetServiceName')
    ->send(
        string $route, // Route to the target service action (example: /user/get)
        array $path = [], 
        array $query = [],
        array $headers = [] 
    );

Making async batch request with parallel processing

$data = $this->get('communicator')
    ->pool(
        'service1', // Target service name
        '/',        // Route to the target service action (example: /user/get)
        [],         // Path parameters to query
        [],         // Post or Get parameters to the query
        []          // Request headers
    )
    ->pool(
        'service1', // Target service name
        '/',        // Route to the target service action (example: /user/get)
        [],         // Path parameters to query
        [],         // Post or Get parameters to the query
        []          // Request headers
        )
    ->fetch();      // Get response from async queries pool

Working with files

make sure you add variables to .env, (*8)

### host url, will be used by another service to get files from current service
HOST_URL=172.18.1.14

###files will be uploaded to this dir
UPLOAD_DIR = public/upload

###should be same for every service using same bus
SCP_USERNAME=www-data
SCP_PASSWORD=KJLgbJ32PIHDJU4

upload files from Request, (*9)

 $handler = $this->get('Garlic\Bus\Service\File\FileHandlerService');
 $handler->handleFiles($_FILES['pictures']);

get file from another service, (*10)

 $uploader = $this->get('Garlic\Bus\Service\File\ScpFileUploadService');
 $uploader->getFile(['host_url' => '172.18.0.1','origin_name' => '1.jpg','path' => 'public/upload/fsdljkahb.jpg']);

The Versions

30/01 2018

dev-master

9999999-dev

Message Bus Bundle uses for communication among microservices through message bus (by default is RabbitMQ)

  Sources   Download

MIT

The Requires

 

by Maksym Churkyn

microservices message bus microservises message bus

30/01 2018

1.0.4

1.0.4.0

Message Bus Bundle uses for communication among microservices through message bus (by default is RabbitMQ)

  Sources   Download

MIT

The Requires

 

by Maksym Churkyn

microservices message bus microservises message bus

29/01 2018

1.0.3

1.0.3.0

Message Bus Bundle uses for communication among microservices through message bus (by default is RabbitMQ)

  Sources   Download

MIT

The Requires

 

by Maksym Churkyn

microservices message bus microservises message bus

29/01 2018

1.0.2

1.0.2.0

Message Bus Bundle uses for communication among microservices through message bus (by default is RabbitMQ)

  Sources   Download

MIT

The Requires

 

by Maksym Churkyn

microservices message bus microservises message bus

16/01 2018

1.0.1

1.0.1.0

Message Bus Bundle uses for communication among microservices through message bus (by default is RabbitMQ)

  Sources   Download

MIT

The Requires

 

by Maksym Churkyn

microservices message bus microservises message bus

13/12 2017

1.0.0

1.0.0.0

Message Bus Bundle uses for communication among microservices through message bus (by default is RabbitMQ)

  Sources   Download

MIT

The Requires

 

by Maksym Churkyn

microservices message bus microservises message bus