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

[zend-queue] Adding support for durable subscribers and persistent message sending #105

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/zend-queue/library/Zend/Queue/Adapter/Activemq.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public function __construct($options, Zend_Queue $queue = null)
$connect->setHeader('passcode', $options['password']);
}

// Support for durable subscriptions
// Must send client-id header in CONNECT AND activemq.subscriptionName in SUBSCRIBE
if(isset($options['client-id'])) {
$connect->setHeader('client-id', $options['client-id']);
}

$response = $this->_client->send($connect)->receive();

if ((false !== $response)
Expand Down Expand Up @@ -204,6 +210,14 @@ protected function _subscribe(Zend_Queue $queue)
$frame->setCommand('SUBSCRIBE');
$frame->setHeader('destination', $queue->getName());
$frame->setHeader('ack', 'client');

// Support for durable subscriptions
// If a client-id is configured in the driver options,
// set the activemq.subscriptionName header with client-id as the value
if(isset($this->_options['driverOptions']['client-id'])) {
$frame->setHeader('activemq.subscriptionName', $this->_options['driverOptions']['client-id']);
}

$this->_client->send($frame);
$this->_subscribed[$queue->getName()] = true;
}
Expand Down Expand Up @@ -292,6 +306,12 @@ public function send($message, Zend_Queue $queue=null)
$frame->setCommand('SEND');
$frame->setHeader('destination', $queue->getName());
$frame->setHeader('content-length', strlen($message));

// If persistent driver option is present, set the persistent header
if(isset($this->_options['driverOptions']['persistent'])) {
$frame->setHeader('persistent', $this->_options['driverOptions']['persistent']);
}

$frame->setBody((string) $message);
$this->_client->send($frame);

Expand Down