Skip to content

Commit

Permalink
repejota#145 : fix reply to inbox for req/res
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylvain Renoir committed Jul 12, 2021
1 parent f08be91 commit a74e811
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Nats/Connection.php
Expand Up @@ -371,19 +371,21 @@ private function handleMSG($line)
{
$parts = explode(' ', $line);
$subject = null;
$inbox = null;
$length = trim($parts[3]);
$sid = $parts[2];

if (count($parts) === 5) {
$length = trim($parts[4]);
$subject = $parts[3];
$subject = $parts[1];
$inbox = $parts[3];
} elseif (count($parts) === 4) {
$length = trim($parts[3]);
$subject = $parts[1];
}

$payload = $this->receive($length);
$msg = new Message($subject, $payload, $sid, $this);
$msg = new Message($subject, $payload, $sid, $this, $inbox);

if (isset($this->subscriptions[$sid]) === false) {
throw Exception::forSubscriptionNotFound($sid);
Expand Down
28 changes: 26 additions & 2 deletions src/Nats/Message.php
Expand Up @@ -24,6 +24,13 @@ class Message
*/
public $body;

/**
* Message Inbox
*
* @var string|null
*/
private $inbox = null;

/**
* Message Ssid.
*
Expand All @@ -47,10 +54,11 @@ class Message
* @param string $sid Message Sid.
* @param Connection $conn Message Connection.
*/
public function __construct($subject, $body, $sid, Connection $conn)
public function __construct($subject, $body, $sid, Connection $conn, $inbox = null)
{
$this->setSubject($subject);
$this->setBody($body);
$this->setInbox($inbox);
$this->setSid($sid);
$this->setConn($conn);
}
Expand Down Expand Up @@ -100,6 +108,22 @@ public function getBody()
return $this->body;
}

/**
* @return string|null
*/
public function getInbox(): ?string
{
return $this->inbox;
}

/**
* @param string|null $inbox
*/
public function setInbox(?string $inbox): void
{
$this->inbox = $inbox;
}

/**
* Set Ssid.
*
Expand Down Expand Up @@ -163,7 +187,7 @@ public function getConn()
public function reply($body)
{
$this->conn->publish(
$this->subject,
$this->inbox,
$body
);
}
Expand Down

0 comments on commit a74e811

Please sign in to comment.