我尝试使用Cro创建一个Rest API,它将在rabbitMQ中发布消息.我想在不同的模块中拆分我的路线,并用"包含"组成它们.但我希望能够在每个模块中与rabbitMQ共享相同的连接.我尝试"我们的",但它不起作用:
档案1:
unit module XXX::YYY;
use Cro::HTTP::Router;
use Cro::HTTP::Server;
use Cro::HTTP::Log::File;
use XXX::YYY::Route1;
use Net::AMQP;
our $rabbitConnection is export = Net::AMQP.new;
await $rabbitConnection.connect;
my $application = route {
include <api v1 run> => run-routes;
}
...
Run Code Online (Sandbox Code Playgroud)
文件2:
unit module XXX::YYY::Route1;
use UUID;
use Cro::HTTP::Router;
use JSON::Fast;
use Net::AMQP;
my $channel = $XXX::YYY::rabbitConnection.open-channel().result;
$channel.declare-queue("test_task", durable=> True );
sub run-routes() is export { ... }
Run Code Online (Sandbox Code Playgroud)
错误信息:
===SORRY!===
No such method 'open-channel' for invocant of type 'Any'
Run Code Online (Sandbox Code Playgroud)
谢谢!