Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC][client] Add ability to send events or commands. #113

Merged
merged 8 commits into from
Jun 9, 2017

Conversation

makasim
Copy link
Member

@makasim makasim commented Jun 9, 2017

  • Events 1 to many
  • Commands 1 to 1 with possibility to get result (optionally)

ref #105

A few examples:

  • Send an event (same as before except the method name, instead of calling send use sendEvent.
<?php

namespace Acme;
use Enqueue\Client\TopicSubscriberInterface;
use Enqueue\Psr\PsrContext;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrProcessor;

/** @var \Enqueue\Client\ProducerV2Interface $producer */

class FooProcessor implements PsrProcessor, TopicSubscriberInterface
{
    public function process(PsrMessage $message, PsrContext $context)
    {
        return self::ACK;
    }

    public static function getSubscribedTopics()
    {
        return ['aFooTopic'];
    }
}

$producer->sendEvent('aFooTopic', 'aMessage');
  • Send command. Fire and forget scenario
<?php

namespace Acme;
use Enqueue\Client\CommandSubscriberInterface;
use Enqueue\Psr\PsrContext;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrProcessor;

class FooProcessor implements PsrProcessor, CommandSubscriberInterface
{
    public function process(PsrMessage $message, PsrContext $context)
    {
        return self::ACK;
    }

    public static function getSubscribedCommand()
    {
        return 'aFooCommand';
    }
}

/** @var \Enqueue\Client\ProducerV2Interface $producer */
$producer->sendCommand('aFooCommand', 'aMessage');
  • Send command and wait for response (non blocking)
<?php
namespace Acme;

use Enqueue\Client\CommandSubscriberInterface;
use Enqueue\Client\Message;
use Enqueue\Consumption\Result;
use Enqueue\Psr\PsrContext;
use Enqueue\Psr\PsrMessage;
use Enqueue\Psr\PsrProcessor;

class FooProcessor implements PsrProcessor, CommandSubscriberInterface
{
    public function process(PsrMessage $message, PsrContext $context)
    {
        return Result::reply($context->createMessage('theReplyMessage'));
    }

    public static function getSubscribedCommand()
    {
        return 'aFooCommand';
    }
}

$message = new Message('aMessage');
$message->setReplyTo('theReplyQueue');

/** @var \Enqueue\Client\ProducerV2Interface $producer */
$promise = $producer->sendCommand('aFooCommand', $message);

$promise->setTimeout(10);
$replyMessage = $promise->getMessage(); // only here's the execution is blocked

* Events 1 to many
* Commands 1 to 1 with possibility to get result (optionally)
@makasim makasim changed the title [client] Add ability to send events or commands. [RFC][client] Add ability to send events or commands. Jun 9, 2017
@makasim makasim merged commit fcb8d09 into master Jun 9, 2017
@makasim makasim deleted the client-envets-and-commands branch June 9, 2017 18:18
ASKozienko pushed a commit that referenced this pull request Nov 2, 2018
[RFC][client] Add ability to send events or commands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants