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

Next Generation #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ sudo: required
language: php

php:
- 7.0
- 7.1
- 7.2
- 7.3
- nightly

cache:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015-2018 Jakub Kulhan <[email protected]>
Copyright (c) 2015-2019 Jakub Kulhan <[email protected]>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
],
"require": {
"php": "~7.0",
"php": "~7.2",
"psr/log": "~1.0",
"react/event-loop": "^1.0 || ^0.5 || ^0.4",
"react/promise": "~2.2"
Expand Down
23 changes: 23 additions & 0 deletions src/Bunny/NG/ClosableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace Bunny\NG;

/**
* Resource that must be explicitly closed.
*
* @author Jakub Kulhan <[email protected]>
*/
interface ClosableInterface
{

/**
* Closes the resource.
*
* After the resource is closed behavior of any of its method is undefined.
*
* If the resource is not closed by calling this method, it will trigger an error in its destructor.
*
* @return void
*/
public function close();

}
12 changes: 12 additions & 0 deletions src/Bunny/NG/RabbitChannelInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace Bunny\NG;

/**
* Channel on the connection to an AMQP 0.9.1 broker.
*
* @author Jakub Kulhan <[email protected]>
*/
interface RabbitChannelInterface extends ClosableInterface
{
// TODO: channel methods
}
54 changes: 54 additions & 0 deletions src/Bunny/NG/RabbitClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
namespace Bunny\NG;

/**
* Client manages message publications and subscriptions.
*
* @author Jakub Kulhan <[email protected]>
*/
interface RabbitClientInterface
{

/**
* Publishes the message on the client-managed connection.
*
* If the client is not connected, a new connection will be opened.
*
* If the connection gets broken, a new one be opened.
*
* All publications use the same channel on the connection.
*
* @param RabbitMessage $message
* @return void
*/
public function publish(RabbitMessage $message);

/**
* Consume from one or more queues on the client-managed connection.
*
* If the client is not connected, a new connection will be opened.
*
* If the connection gets broken and there are messages that has been handed over to the application, however,
* that weren't acknowledged, rejected, or nacked, an exception will be thrown. Otherwise a new connection will
* be opened.
*
* Every subscription gets a new channel. However, all consumers of the subscription share that channel.
*
* @return RabbitSubscriptionInterface
*/
public function subscribe(): RabbitSubscriptionInterface;

/**
* Send heartbeat on the client-managed connection.
*
* If the client is not connected, a new connection will be opened.
*
* This method is supposed to be called either if the application tries to verify that the broker is available,
* or it received a message on a subscription and it knows that the heartbeat timeout would be triggered. Otherwise,
* e.g. when a subscription waits for new messages, heartbeats get sent automatically.
*
* @return void
*/
public function ping();

}
19 changes: 19 additions & 0 deletions src/Bunny/NG/RabbitConnectionFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace Bunny\NG;

/**
* @author Jakub Kulhan <[email protected]>
*/
interface RabbitConnectionFactoryInterface
{

/**
* Opens a new connection with the factory connection options.
*
* Returned connection is not managed by the instance and must be explicitly closed by its `close()` method.
*
* @return RabbitConnectionInterface
*/
public function newConnection(): RabbitConnectionInterface;

}
19 changes: 19 additions & 0 deletions src/Bunny/NG/RabbitConnectionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace Bunny\NG;

/**
* Connection to an AMQP 0.9.1 broker.
*
* @author Jakub Kulhan <[email protected]>
*/
interface RabbitConnectionInterface extends ClosableInterface
{

/**
* Opens a new channel on the connection.
*
* @return RabbitChannelInterface
*/
public function newChannel(): RabbitChannelInterface;

}
158 changes: 158 additions & 0 deletions src/Bunny/NG/RabbitConnectionOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?php
namespace Bunny\NG;

use Bunny\NG\Sasl\SaslMechanismInterface;

/**
* @author Jakub Kulhan <[email protected]>
*/
final class RabbitConnectionOptions
{

/**
* Hostname or IP address of the server.
*
* @var string
*/
public $host;

/**
* Server port.
*
* @var int
*/
public $port;

/**
* Available SASL mechanisms.
*
* @var SaslMechanismInterface[]
*/
public $mechanisms;

/**
* Server virtual host.
*
* @var string
*/
public $virtualHost;

/**
* Heartbeat timeout defines max time the connection will be kept idle. Every `heartbeat` seconds the client will send
* heartbeat frame to the server. If client doesn't hear from the server in `heartbeat * 2` seconds, the connection
* is assumed to be dead.
*
* @var float
*/
public $heartbeat;

/**
* Timeout to establish the connection (connection parameters tuning, SASL exchange, opening virtual host).
*
* @var float
*/
public $connectTimeout;

/**
* Parameters for TLS-secured connections.
*
* @var TlsOptions|null
*/
public $tls;

public static function new()
{
return new static();
}

public static function fromUrl(string $url)
{
throw new \LogicException("TODO");
}

/**
* @param string $host
* @return self
*/
public function setHost(string $host)
{
$this->host = $host;
return $this;
}

/**
* @param int $port
* @return self
*/
public function setPort(int $port)
{
$this->port = $port;
return $this;
}

/**
* @param SaslMechanismInterface[] $mechanisms
* @return self
*/
public function setMechanisms(array $mechanisms)
{
$this->mechanisms = $mechanisms;
return $this;
}

/**
* @param SaslMechanismInterface $mechanism
* @return self
*/
public function addMechanism(SaslMechanismInterface $mechanism)
{
if ($this->mechanisms === null) {
$this->mechanisms = [];
}

$this->mechanisms[] = $mechanism;

return $this;
}

/**
* @param string $virtualHost
* @return self
*/
public function setVirtualHost(string $virtualHost)
{
$this->virtualHost = $virtualHost;
return $this;
}

/**
* @param float $heartbeat
* @return self
*/
public function setHeartbeat(float $heartbeat)
{
$this->heartbeat = $heartbeat;
return $this;
}

/**
* @param float $connectTimeout
* @return self
*/
public function setConnectTimeout(float $connectTimeout)
{
$this->connectTimeout = $connectTimeout;
return $this;
}

/**
* @param TlsOptions|null $tls
* @return self
*/
public function setTls(?TlsOptions $tls)
{
$this->tls = $tls;
return $this;
}

}
49 changes: 49 additions & 0 deletions src/Bunny/NG/RabbitConsumerOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
namespace Bunny\NG;

/**
* @author Jakub Kulhan <[email protected]>
*/
final class RabbitConsumerOptions
{

/**
* Queue name.
*
* @var string
*/
public $queue;

/**
* Consumer tag.
*
* @var string
*/
public $consumerTag;

public static function new()
{
return new static();
}

/**
* @param string $queue
* @return self
*/
public function setQueue(string $queue)
{
$this->queue = $queue;
return $this;
}

/**
* @param string $consumerTag
* @return self
*/
public function setConsumerTag(string $consumerTag)
{
$this->consumerTag = $consumerTag;
return $this;
}

}
10 changes: 10 additions & 0 deletions src/Bunny/NG/RabbitMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Bunny\NG;

/**
* @author Jakub Kulhan <[email protected]>
*/
final class RabbitMessage
{
// TODO
}
Loading