Download the PHP package lushdigital/microservice-aggregator-transport without Composer
On this page you can find all versions of the php package lushdigital/microservice-aggregator-transport. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lushdigital/microservice-aggregator-transport
More information about lushdigital/microservice-aggregator-transport
Files in lushdigital/microservice-aggregator-transport
Package microservice-aggregator-transport
Short Description A set of convenience classes and interfaces for simplifying aggregation of data from multiple microservices.
License MIT
Informations about the package microservice-aggregator-transport
Lush Digital - Micro Service Aggregator Transport
A set of convenience classes and interfaces for simplifying aggregation of data from multiple microservices.
The purpose of the package is to provide a reliable, testable and easy to use means of communicating with microservices within a service oriented architecture.
Package Contents
- Service interface
- Service abstract class
- Cloud service interface
- Cloud service abstract class
- Request class
Installation
Install the package as normal:
Copy the src/config/transport.php
file into your config
folder in the root of your app.
Finally add the following line to your bootstrap/app.php
file:
Creating a Service
The first thing you need to do to utilise this package is to create a class to interact with your service.
This class will extend one of the base classes this package provides; you add your own methods for each endpoint of the service you want to access.
Local Service
A 'local' service is used when you can communicate with a service via some kind of local DNS. In that you do not need to call out over the internet to access the service. For example you might be using Kubernetes DNS.
Before you can create a cloud service you need to ensure the following config options are set (explicitly or via environment variables):
transport.branch
- The CI branch. For example master.transport.environment
- The CI environment. For example dev or staging.
Then for each local service, you must define:
transport.services.local.SERVICE_NAME.uri
- The URI of the local service.
You can also optionally specify a version of a service:
transport.services.local.SERVICE_NAME.version
- The version of the local service.
To create a local service you need to extend the \LushDigital\MicroserviceAggregatorTransport\Service
class:
As you can see in this service we have created a method which calls a
POST
endpoint to save a thing.
Cloud Service
A cloud service is used when you need to communicate with a service over the internet. The assumption is that the service is accessed via some kind of API gateway and can't be accessed directly.
Before you can create a cloud service you need to ensure the following config options are set (explicitly or via environment variables):
transport.branch
- The CI branch. For example master.transport.domain
- The top level domain of the service environment.transport.gateway_uri
- The URI of the API gateway.transport.environment
- The CI environment. For example dev or staging.
Then for each cloud service, you must define:
transport.services.cloud.SERVICE_NAME.uri
- The URI of the cloud service.transport.auth.SERVICE_NAME.email
- The email address of a service account used to access the cloud service.transport.auth.SERVICE_NAME.password
- The password of a service account used to access the cloud service.
You can also optionally specify a version of a service:
transport.services.cloud.SERVICE_NAME.version
- The version of the cloud service.
Then you can define your service:
As you can the service looks very similar to a local one. The only major difference is the base class. The base class does all the heavy lifting of authentication and API gateway routing so you don't have to!
Using a Service
Once you have created your service it can be used just like any other PHP class. Think of them like you would a repository object in a database environment.
Example usage in a controller:
Asynchronous Requests
In some situations you made need to make multiple requests in quick succession. This can often be improved by running the requests concurrently. The package utilises Guzzle promises to do just that. First you need to define a service with an asynchronous call:
You can then use this in your controller: