stomp-php / stomp-bundle
为 symfony 应用程序集成 stomp-php 支持。
dev-master
2019-07-21 07:20 UTC
Requires
- php: ^7.1
- stomp-php/stomp-php: ^4.4
- symfony/config: ^3.4|^4.0
- symfony/console: ^3.4|^4.0
- symfony/dependency-injection: ^3.4|^4.0
- symfony/http-kernel: ^3.4|^4.0
- symfony/yaml: ^3.4|^4.0
Requires (Dev)
- phpunit/phpunit: ^6|^7
- symfony/debug: ^3.4|^4.0
This package is auto-updated.
Last update: 2024-08-24 01:13:28 UTC
README
此包为 symfony (3.4, 4.0) 提供了 stomp-php 集成。
快速设置
composer require stomp-php/stomp-bundle
- 对于 Symfony 3.4,您需要在
AppKernel.php
中添加new StompPhp\StompBundle\StompPhpStompBundle()
来注册此包。 - 对于 Symfony 4.0,您需要在
services.yaml
中添加StompPhp\StompBundle\Command\ConsumerCommand:
来注册命令。
创建一个可调用的服务。
class YourService { // is called for every message that is received from the queue public function __invoke(Stomp\Transport\Frame $message) { if ($mesage->body === '...') { return true; } return false; } }
定义 stomp 客户端和消费者(订阅)。
stomp_php_stomp: clients: default: broker_uri: 'tcp://:61614' # default read timeout is one minute, which makes interactive stop requests very slow. read_timeout_ms: 750 consumers: welcome: client: 'default' queue: '/welcome' service: AppBundle\YourService
开始消费消息。
bin/console stomp:consumer welcome
配置选项
请注意,客户端实例不是共享的,并且默认情况下是私有的。
消费者始终是公共的,因为它们是此包提供的动态控制台命令的一部分。
stomp_php_stomp: clients: default: # use a broker_uri as connection string # failover://(tcp://:61614,ssl://:61612)?randomize=true # failover://(tcp://:61614,ssl://:61612) broker_uri: 'tcp://:61614' # expose this client as service (stomp.clients.default) public: true example_broker: host: '127.0.0.1' port: 61612 vhost: '/someVhost' # define heartbeats, please be aware that your processing # needs to be faster than the heartbeat that you defined here. heartbeat_client_ms: 250 heartbeat_server_ms: 250 read_timeout_ms: 750 write_timeout: 3 simple_broker: broker_uri: 'failover://(tcp://:61614,ssl://:61612)?randomize=true' # define username and password user: 'username' password: 'password' consumers: welcome: # set the client to use client: 'default' # define what queue to subscribe to queue: '/welcome' # set the service (callable) service: AppBundle\Service\WelcomeService welcome_with_method: client: 'example_broker' queue: '/push/message' service: AppBundle\Service\MessageService # set the service method (if service itself is not a callable) service_method: 'onPushMessage' # define a message selector selector: "switch = 'green'"