diff --git a/example/sender b/example/sender index fcf9574..f93bbb6 100755 --- a/example/sender +++ b/example/sender @@ -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); } diff --git a/lib/Stomp/Client.rakumod b/lib/Stomp/Client.rakumod index 9c2ca86..9b942f9 100644 --- a/lib/Stomp/Client.rakumod +++ b/lib/Stomp/Client.rakumod @@ -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; } diff --git a/t/client.rakutest b/t/client.rakutest index df2d50e..f23e9f8 100644 --- a/t/client.rakutest +++ b/t/client.rakutest @@ -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; @@ -83,6 +83,13 @@ my \TestableClient = Stomp::Client but role { $message = Stomp::Parser.parse(await $test-conn.sent-data).made; is $message.headers, $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, $test-type, "can set content-type header"; + is $message.headers, '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; diff --git a/t/server.rakutest b/t/server.rakutest index d71aa5f..1e633dc 100644 --- a/t/server.rakutest +++ b/t/server.rakutest @@ -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 { @@ -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' ); @@ -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',