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
5 changes: 0 additions & 5 deletions src/Micro/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,4 @@ public function replyTo(): ?string
{
return $this->msg->replyTo;
}

public function msg(): Message
{
return $this->msg;
}
}
6 changes: 0 additions & 6 deletions src/Micro/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Sofascore\Nats\Micro;

use Sofascore\Nats\Headers;
use Sofascore\Nats\Message;

interface RequestInterface
{
Expand All @@ -22,9 +21,4 @@ public function headers(): ?Headers;
public function subject(): string;

public function replyTo(): ?string;

/**
* Returns the raw underlying NATS message.
*/
public function msg(): Message;
}
44 changes: 27 additions & 17 deletions tests/Integration/Micro/ServiceExtendedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Sofascore\Nats\Tests\Integration\Micro;

use Sofascore\Nats\Connection;
use Sofascore\Nats\Headers;
use Sofascore\Nats\Message;
use Sofascore\Nats\Micro\EndpointConfig;
use Sofascore\Nats\Micro\RequestInterface;
Expand Down Expand Up @@ -78,37 +79,46 @@ public function testServiceId(): void
$svc2->stop();
}

public function testRequestMsg(): void
public function testRequestExposesInboundMetadataWithoutRawMessage(): void
{
$svcName = 'reqmsg-test-' . substr(uniqid(), -6);
$subject = 'svc.reqmsg.' . substr(uniqid(), -6);
$svcName = 'reqmeta-test-' . substr(uniqid(), -6);
$subject = 'svc.reqmeta.' . substr(uniqid(), -6);

/** @var Message|null $capturedMsg */
$capturedMsg = null;
$capturedData = null;
$capturedSubject = null;
$capturedReplyTo = null;
$capturedHeader = null;

$svc = Service::create($this->conn, new ServiceConfig(
name: $svcName,
version: '1.0.0',
));

$svc->addEndpoint('echo', function (RequestInterface $req) use (&$capturedMsg): void {
// Call msg() to get the underlying Message
$capturedMsg = $req->msg();
$svc->addEndpoint('echo', function (RequestInterface $req) use (
&$capturedData,
&$capturedSubject,
&$capturedReplyTo,
&$capturedHeader,
): void {
$capturedData = $req->data();
$capturedSubject = $req->subject();
$capturedReplyTo = $req->replyTo();
$capturedHeader = $req->headers()?->get('X-Request-Id');

// Respond with the data
$req->respond('got: ' . $req->data());
}, new EndpointConfig(subject: $subject));

$reply = $this->conn->request($subject, 'hello-world', 2.0);
$reply = $this->conn->requestMessage(new Message(
subject: $subject,
data: 'hello-world',
headers: new Headers(['X-Request-Id' => 'req-42']),
), 2.0);

self::assertSame('got: hello-world', $reply->data);

// Verify that msg() returned a Message instance
self::assertNotNull($capturedMsg, 'req->msg() should have returned a Message');
self::assertInstanceOf(Message::class, $capturedMsg);
self::assertSame('hello-world', $capturedMsg->data);
self::assertSame($subject, $capturedMsg->subject);
self::assertNotNull($capturedMsg->replyTo, 'Request message should have a replyTo subject');
self::assertSame('hello-world', $capturedData);
self::assertSame($subject, $capturedSubject);
self::assertNotNull($capturedReplyTo, 'Request should expose the reply subject');
self::assertSame('req-42', $capturedHeader);

$svc->stop();
}
Expand Down