Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions src/Contracts/Queue/ConnectionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Contracts\Queue;

/**
* Builds a Context: the entry point of every adapter.
*/
interface ConnectionFactory
{
/**
* Creates a context (a session/connection to the transport).
*
* @return Context
*/
public function createContext(): Context;
}
56 changes: 56 additions & 0 deletions src/Contracts/Queue/Consumer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Contracts\Queue;

/**
* Receives messages from a single queue.
*/
interface Consumer
{
/**
* Acknowledges the message; the transport may then discard it.
*
* @param Message $message
* @return void
*/
public function acknowledge(Message $message): void;

/**
* Returns the queue this consumer reads from.
*
* @return Queue
*/
public function getQueue(): Queue;

/**
* Receives a message, blocking up to timeout milliseconds (0 = block
* until one is available). Returns null when none arrives in time.
*
* @param int $timeout
* @return Message|null
*/
public function receive(int $timeout = 0): Message|null;

/**
* Receives a message without blocking, or null when none is ready.
*
* @return Message|null
*/
public function receiveNoWait(): Message|null;

/**
* Rejects the message. When requeue is true the transport redelivers it.
*
* @param Message $message
* @param bool $requeue
* @return void
*/
public function reject(Message $message, bool $requeue = false): void;
}
87 changes: 87 additions & 0 deletions src/Contracts/Queue/Context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Contracts\Queue;

/**
* A session with the transport. Factory for messages, destinations,
* producers and consumers.
*/
interface Context
{
/**
* Closes the context and releases its resources.
*
* @return void
*/
public function close(): void;

/**
* Creates a consumer for the given destination.
*
* @param Destination $destination
* @return Consumer
*/
public function createConsumer(Destination $destination): Consumer;

/**
* Creates a message with an optional body, properties and headers.
*
* @param string $body
* @param array $properties
* @param array $headers
* @return Message
*/
public function createMessage(string $body = '', array $properties = [], array $headers = []): Message;

/**
* Creates a producer.
*
* @return Producer
*/
public function createProducer(): Producer;

/**
* Creates a queue destination by name.
*
* @param string $queueName
* @return Queue
*/
public function createQueue(string $queueName): Queue;

/**
* Creates a subscription consumer for consuming from several queues.
*
* @return SubscriptionConsumer
*/
public function createSubscriptionConsumer(): SubscriptionConsumer;

/**
* Creates a temporary queue tied to the lifetime of the context.
*
* @return Queue
*/
public function createTemporaryQueue(): Queue;

/**
* Creates a topic destination by name.
*
* @param string $topicName
* @return Topic
*/
public function createTopic(string $topicName): Topic;

/**
* Removes all messages from the given queue.
*
* @param Queue $queue
* @return void
*/
public function purgeQueue(Queue $queue): void;
}
17 changes: 17 additions & 0 deletions src/Contracts/Queue/Destination.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Contracts\Queue;

/**
* Marker interface for a message destination: a Queue or a Topic.
*/
interface Destination
{
}
173 changes: 173 additions & 0 deletions src/Contracts/Queue/Message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php

/* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Phalcon\Contracts\Queue;

/**
* A message exchanged through the transport. Carries a body, application
* properties, transport headers and the standard messaging metadata.
*/
interface Message
{
/**
* Returns the message body.
*
* @return string
*/
public function getBody(): string;

/**
* Returns the correlation id used to correlate request/reply messages.
*
* @return string|null
*/
public function getCorrelationId(): string|null;

/**
* Returns a single header value, or the default when it is not set.
*
* @param string $name
* @param mixed $defaultValue
* @return mixed
*/
public function getHeader(string $name, $defaultValue = null): mixed;

/**
* Returns all transport headers.
*
* @return array
*/
public function getHeaders(): array;

/**
* Returns the message id.
*
* @return string|null
*/
public function getMessageId(): string|null;

/**
* Returns all application properties.
*
* @return array
*/
public function getProperties(): array;

/**
* Returns a single property value, or the default when it is not set.
*
* @param string $name
* @param mixed $defaultValue
* @return mixed
*/
public function getProperty(string $name, $defaultValue = null): mixed;

/**
* Returns the reply-to destination name.
*
* @return string|null
*/
public function getReplyTo(): string|null;

/**
* Returns the timestamp (in milliseconds) or null when it is not set.
*
* @return int|null
*/
public function getTimestamp(): int|null;

/**
* Whether the message has been redelivered.
*
* @return bool
*/
public function isRedelivered(): bool;

/**
* Sets the message body.
*
* @param string $body
* @return void
*/
public function setBody(string $body): void;

/**
* Sets the correlation id.
*
* @param string $correlationId
* @return void
*/
public function setCorrelationId(string $correlationId): void;

/**
* Sets a single transport header.
*
* @param string $name
* @param mixed $value
* @return void
*/
public function setHeader(string $name, $value): void;

/**
* Replaces all transport headers.
*
* @param array $headers
* @return void
*/
public function setHeaders(array $headers): void;

/**
* Sets the message id.
*
* @param string $messageId
* @return void
*/
public function setMessageId(string $messageId): void;

/**
* Replaces all application properties.
*
* @param array $properties
* @return void
*/
public function setProperties(array $properties): void;

/**
* Sets a single application property.
*
* @param string $name
* @param mixed $value
* @return void
*/
public function setProperty(string $name, $value): void;

/**
* Marks the message as redelivered.
*
* @param bool $redelivered
* @return void
*/
public function setRedelivered(bool $redelivered): void;

/**
* Sets the reply-to destination name.
*
* @param string $replyTo
* @return void
*/
public function setReplyTo(string $replyTo): void;

/**
* Sets the timestamp (in milliseconds).
*
* @param int $timestamp
* @return void
*/
public function setTimestamp(int $timestamp): void;
}
Loading
Loading