当前,我们正在设计客户端应用程序,以使用Perl中的Mojolicious库通过WebSocket与stomp应用程序进行交互,但是MOJO没有STOMP命令(http://stomp.github.io/stomp-specification-1.0.html)的连接,订阅和断开连接方法,并且一些示例命令提供了如以下所说的, 我们需要设计这些命令的代码以连接stomp应用
$ua->websocket_p('wss://ws.autorentals.com/async_rates')->then(sub {
my $tx = shift;
my $promise = Mojo::Promise->new;
$tx->on(finish => sub { $promise->resolve });
$tx->on(message => sub {
my ($tx, $msg) = @_;
say "WebSocket message: $msg";
$tx->finish;
});
$tx->send('Hi!');
return $promise;
})->catch(sub {
my $err = shift;
warn "WebSocket error: $err";
})->wait;
CONNECT
login: <username>
passcode:<passcode>
^@
SUBSCRIBE
destination: /queue/foo
ack: client
^@
SEND
destination:/queue/a
hello queue a
^@