参考资料:https://github.com/php-amqplib/RabbitMqBundle
申明:本文只是针对使用Symfony框架使用Rabbit的一些简单的方法,前提是需要的扩展和服务都已经搭建完毕。具体需要的东西会在后面有时间的时候补充(请谅解)。
注意:symfony 版本是:Symfony 4.2.5 (env: dev, debug: true)
使用:bin/console --version 可以查看版本
1.安装bunddle(安装的时候会询问,是否自动注册,yes就可以了)
$ composer require php-amqplib/rabbitmq-bundle
2.开始使用:
1)创建配置(该配置也可以写在其他地方,不过,安装的时候yes之后会自己创建好一个old_sound_rabbit_mq.yaml)我就直接在这里配置了。
// config/packages/old_sound_rabbit_mq.yaml
old_sound_rabbit_mq:
connections:
default:
host: 'ip'
port: 5672
user: 'admin'
password: 'admin'
vhost: '/'
lazy: true
connection_timeout: 3
read_write_timeout: 6
# requires php-amqplib v2.4.1+ and PHP5.4+
keepalive: false
# requires php-amqplib v2.4.1+
heartbeat: 0
#requires php_sockets.dll
use_socket: true # default false
another:
# A different (unused) connection defined by an URL. One can omit all parts,
# except the scheme (amqp:). If both segment in the URL and a key value (see above)
# are given the value from the URL takes precedence.
# See https://www.rabbitmq.com/uri-spec.html on how to encode values.
# url: 'amqp://guest:password@localhost:5672/vhost?lazy=1&connection_timeout=6'
producers:
emailing:
connection: default
exchange_options: {name: 'emails', type: direct}
service_alias: my_app_service # no alias by default
consumers:
emailing:
connection: default
exchange_options: {name: 'emails', type: direct}
queue_options: {name: 'emails'}
callback: email_service
暂时写到这里。后续完善。