Symfony Use RabbitMQ

参考资料: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

 

暂时写到这里。后续完善。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值