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

Create a MessagePublisher service #467

Closed
dannylamb opened this issue Dec 16, 2016 · 3 comments
Closed

Create a MessagePublisher service #467

dannylamb opened this issue Dec 16, 2016 · 3 comments
Assignees

Comments

@dannylamb
Copy link
Contributor

dannylamb commented Dec 16, 2016

Depends on #466

We need to create a service to publish messages from Drupal. It should have a basic interface

interface MessagePublisher {
  public function publish($broker_url, $queue, $msg, array $headers);
}

Our implementation class should use STOMP, and will essentially look like this:

$queue  = '/queue/foo';
$msg    = 'bar';

/* connection */
try {
    $stomp = new Stomp('tcp://localhost:61613');
} catch(StompException $e) {
    die('Connection failed: ' . $e->getMessage());
}

/* send a message to the queue 'foo' */
$stomp->send($queue, $msg);

/* close connection */
unset($stomp);

We'll need to write a Kernel test for this service, pulling it out of the dependency injection container, publishing a message with our publish function, and then reading from the queue to see if the message has been received. You can check for a message using code like this:

$queue  = '/queue/foo';
$msg    = 'bar';

/* connection */
try {
    $stomp = new Stomp('tcp://localhost:61613');
} catch(StompException $e) {
    die('Connection failed: ' . $e->getMessage());
}

/* subscribe to messages from the queue 'foo' */
$stomp->subscribe($queue);

/* read a frame */
$frame = $stomp->readFrame();

$this->assertTrue($frame->body == $msg, "Queue must contain sent message");

unset($stomp);

The only caveat here is that the broker url will come from the islandora module's configuration.

@dannylamb
Copy link
Contributor Author

I'll tackle this one for some pre-Xmas fun.

@dannylamb
Copy link
Contributor Author

So.... turns out the php stomp pecl extension is not supported in php7. So I need to use this: https://github.com/stomp-php/stomp-php. Which is good. It knows to block until a message has been received and handles things a bit nicer. But it's on packagist. So we need to start using composer, which leads to a lot of big changes. Like #474 and #475

@dannylamb
Copy link
Contributor Author

So I can close this and will just re-assign the broadcast action issue to mysef: #468

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant