Skip to content
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
4 changes: 2 additions & 2 deletions example/sender
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

use Stomp::Client;

sub MAIN(Str $message = 'Hello, World', :$login = 'guest', :$password = 'guest', :$port = 61613, :$host = 'localhost', :$queue = 'stomptest') {
sub MAIN(Str $message = 'Hello, World', :$login = 'guest', :$password = 'guest', :$port = 61613, :$host = 'localhost', :$queue = 'stomptest', *%headers) {

my $client = Stomp::Client.new(:$login, :$password, :$port, :$host);

await $client.connect;

$client.send($queue, $message);
$client.send($queue, $message, |%headers);
}

4 changes: 2 additions & 2 deletions lib/Stomp/Client.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class Stomp::Client does Stomp::MessageStream[Stomp::Parser::ServerCommands] {
IO::Socket::Async
}

method send($destination, $body, :$content-type = "text/plain") {
method send($destination, $body, :$content-type = "text/plain", *%headers) {
self!ensure-connected;
$!connection.print: Stomp::Message.new:
command => 'SEND',
headers => ( :$destination, :$content-type ),
headers => ( :$destination, :$content-type, %headers ),
body => $body;
}

Expand Down
9 changes: 8 additions & 1 deletion t/client.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use Test;
use Test::IO::Socket::Async;
use Stomp;

plan 31;
plan 33;

constant $test-host = 'localhost';
constant $test-port = 1234;
Expand Down Expand Up @@ -83,6 +83,13 @@ my \TestableClient = Stomp::Client but role {
$message = Stomp::Parser.parse(await $test-conn.sent-data).made;
is $message.headers<content-type>, $test-type, "can set content-type header";

$send-promise = $client.send($test-destination, $test-body,
content-type => $test-type, random-header => 'random-value');
$message = Stomp::Parser.parse(await $test-conn.sent-data).made;
is $message.headers<content-type>, $test-type, "can set content-type header";
is $message.headers<random-header>, 'random-value', "can set different header";


my $sub-supply = $client.subscribe($test-destination);
isa-ok $sub-supply, Supply, "subscribe returns a Supply";
my $sent-data-promise = $test-conn.sent-data;
Expand Down
9 changes: 7 additions & 2 deletions t/server.rakutest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use Test;
use Test::IO::Socket::Async;
use Stomp;

plan 28;
plan 30;

constant $test-socket = Test::IO::Socket::Async.new;
my \TestableServer = Stomp::Server but role {
Expand Down Expand Up @@ -96,7 +96,8 @@ dies-ok { TestableServer.new(port => $test-port) }, "Must provide host and port
my $match-message = Stomp::Message.new(
command => 'SEND',
headers => (
:$destination
:$destination,
random-header => 'random-value'
),
body => 'Test Message'
);
Expand All @@ -121,6 +122,10 @@ dies-ok { TestableServer.new(port => $test-port) }, "Must provide host and port
await Promise.anyof($rec-promise, Promise.in(5));

is $rec-message.body, $match-message.body, "got the message from published-messages";
for $match-message.headers.kv -> $k, $v {
is $rec-message.headers{$k}, $v, "got expected header $k";
}


$test-conn.receive-data: Stomp::Message.new(
command => 'UNSUBSCRIBE',
Expand Down
Loading