/**
  * Discovery for previously defined service should return defined service.
  */
 public function testDiscoveryOfDefinedService()
 {
     $endpointA = $this->serviceBus->define('calc');
     $endpointB = $this->serviceBus->discover('calc');
     $this->assertSame($endpointA, $endpointB);
 }
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Seven\Component\MessageBusClient\ServiceBus;
use Seven\Component\MessageBusClient\Message\Request;
use Seven\Component\MessageBusClient\Protocol\JSONRPC;
$env = function ($key, $default = null) {
    return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
};
$driver = new JSONRPC\Driver($env('JSON_RPC_URL', 'http://localhost:8000/json-rpc'));
$bus = new ServiceBus($driver);
// Make a call
$promise = $bus->discover('calc')->call(new Request('div', '1', ['a' => 10, 'b' => 5]));
// Wait for response
$response = $promise->resolve();
// Should be 2
var_export($response->getValue());
echo PHP_EOL;
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Seven\Component\MessageBusClient\ServiceBus;
use Seven\Component\MessageBusClient\Encoder\JsonEncoder;
use Seven\Component\MessageBusClient\Message\Request;
use Seven\Component\MessageBusClient\Protocol\AMQP;
use PhpAmqpLib\Connection\AMQPStreamConnection;
$env = function ($key, $default = null) {
    return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
};
$connection = new AMQPStreamConnection($env('AMQP_HOST', 'localhost'), $env('AMQP_PORT', 5672), $env('AMQP_USER', 'guest'), $env('AMQP_PASSWORD', 'guest'), $env('AMQP_VHOST', '/'));
$channel = $connection->channel();
$driver = new AMQP\Driver($channel, 'outbox', new JsonEncoder());
$bus = new ServiceBus($driver);
// Publish a message asynchronously
$bus->discover('category_repository')->publish(new Request('category_repository.updated', '1.0', ['category' => ['name' => 'Fruits', 'position' => 10]]));
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Seven\Component\MessageBusClient\ServiceBus;
use Seven\Component\MessageBusClient\Encoder\JsonEncoder;
use Seven\Component\MessageBusClient\Message\Request;
use Seven\Component\MessageBusClient\Protocol\AMQP;
use PhpAmqpLib\Connection\AMQPStreamConnection;
$env = function ($key, $default = null) {
    return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
};
$connection = new AMQPStreamConnection($env('AMQP_HOST', 'localhost'), $env('AMQP_PORT', 5672), $env('AMQP_USER', 'guest'), $env('AMQP_PASSWORD', 'guest'), $env('AMQP_VHOST', '/'));
$channel = $connection->channel();
$driver = new AMQP\Driver($channel, 'outbox', new JsonEncoder());
$bus = new ServiceBus($driver);
// Make a call
$promise = $bus->discover('category_repository')->call(new Request('category_repository.find', '1.0', ['query' => ['offset' => 10, 'size' => 10]]));
// Wait for response
$response = $promise->resolve();
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Seven\Component\MessageBusClient\Driver\SplitDriver;
use Seven\Component\MessageBusClient\ServiceBus;
use Seven\Component\MessageBusClient\Encoder\JsonEncoder;
use Seven\Component\MessageBusClient\Message\Request;
use Seven\Component\MessageBusClient\Protocol\AMQP;
use Seven\Component\MessageBusClient\Protocol\JSONRPC;
use PhpAmqpLib\Connection\AMQPStreamConnection;
$env = function ($key, $default = null) {
    return isset($_SERVER[$key]) ? $_SERVER[$key] : $default;
};
// Build AMQP Driver
$connection = new AMQPStreamConnection($env('AMQP_HOST', 'localhost'), $env('AMQP_PORT', 5672), $env('AMQP_USER', 'guest'), $env('AMQP_PASSWORD', 'guest'), $env('AMQP_VHOST', '/'));
$channel = $connection->channel();
$amqp = new AMQP\Driver($channel, 'outbox', new JsonEncoder());
// Build JSON RPC Driver
$jsonrpc = new JSONRPC\Driver($env('JSON_RPC_URL', 'http://localhost:8000/json-rpc'));
// Create instance of split driver and use JSON RPC as sync and AMQP as async
$bus = new ServiceBus(new SplitDriver($jsonrpc, $amqp));
// Asynchronously published message will use AMPQ driver
$bus->discover('category_repository')->publish(new Request('category_repository.updated', '1.0', ['category' => ['name' => 'Fruits', 'position' => 10]]));
// Synchronously published message will use JSON RPC driver
$response = $bus->discover('category_repository')->call(new Request('category_repository.updated', '1.0', ['category' => ['name' => 'Fruits', 'position' => 10]]))->resolve();