2
2
3
3
namespace Enqueue \Client ;
4
4
5
- use Enqueue \Client \Driver \RabbitMqDriver ;
6
5
use Enqueue \Client \Driver \RabbitMqStompDriver ;
7
6
use Enqueue \Client \Driver \StompManagementClient ;
8
7
use Enqueue \Dsn \Dsn ;
9
- use Enqueue \Stomp \StompConnectionFactory ;
10
- use Interop \Amqp \AmqpConnectionFactory ;
11
8
use Interop \Queue \ConnectionFactory ;
12
9
13
10
final class DriverFactory implements DriverFactoryInterface
@@ -25,36 +22,8 @@ public function create(ConnectionFactory $factory, Config $config, RouteCollecti
25
22
if ($ driverInfo = $ this ->findDriverInfo ($ dsn , Resources::getAvailableDrivers ())) {
26
23
$ driverClass = $ driverInfo ['driverClass ' ];
27
24
28
- if (RabbitMqDriver::class === $ driverClass ) {
29
- if (false == $ factory instanceof AmqpConnectionFactory) {
30
- throw new \LogicException (sprintf (
31
- 'The factory must be instance of "%s", got "%s" ' ,
32
- AmqpConnectionFactory::class,
33
- get_class ($ factory )
34
- ));
35
- }
36
-
37
- return new RabbitMqDriver ($ factory ->createContext (), $ config , $ collection );
38
- }
39
-
40
25
if (RabbitMqStompDriver::class === $ driverClass ) {
41
- if (false == $ factory instanceof StompConnectionFactory) {
42
- throw new \LogicException (sprintf (
43
- 'The factory must be instance of "%s", got "%s" ' ,
44
- StompConnectionFactory::class,
45
- get_class ($ factory )
46
- ));
47
- }
48
-
49
- $ managementClient = StompManagementClient::create (
50
- ltrim ($ dsn ->getPath (), '/ ' ),
51
- $ dsn ->getHost () ?: 'localhost ' ,
52
- $ config ->getDriverOption ('management_plugin_port ' , 15672 ),
53
- (string ) $ dsn ->getUser (),
54
- (string ) $ dsn ->getPassword ()
55
- );
56
-
57
- return new RabbitMqStompDriver ($ factory ->createContext (), $ config , $ collection , $ managementClient );
26
+ return $ this ->createRabbitMqStompDriver ($ factory , $ dsn , $ config , $ collection );
58
27
}
59
28
60
29
return new $ driverClass ($ factory ->createContext (), $ config , $ collection );
@@ -111,4 +80,20 @@ private function findDriverInfo(Dsn $dsn, array $factories): ?array
111
80
112
81
return null ;
113
82
}
83
+
84
+ private function createRabbitMqStompDriver (ConnectionFactory $ factory , Dsn $ dsn , Config $ config , RouteCollection $ collection ): RabbitMqStompDriver
85
+ {
86
+ $ defaultManagementHost = $ dsn ->getHost () ?: $ config ->getTransportOption ('host ' , 'localhost ' );
87
+ $ managementVast = ltrim ($ dsn ->getPath (), '/ ' ) ?: $ config ->getTransportOption ('vhost ' , '/ ' );
88
+
89
+ $ managementClient = StompManagementClient::create (
90
+ urldecode ($ managementVast ),
91
+ $ config ->getDriverOption ('rabbitmq_management_host ' , $ defaultManagementHost ),
92
+ $ config ->getDriverOption ('rabbitmq_management_port ' , 15672 ),
93
+ (string ) $ dsn ->getUser () ?: $ config ->getTransportOption ('user ' , 'guest ' ),
94
+ (string ) $ dsn ->getPassword () ?: $ config ->getTransportOption ('pass ' , 'guest ' )
95
+ );
96
+
97
+ return new RabbitMqStompDriver ($ factory ->createContext (), $ config , $ collection , $ managementClient );
98
+ }
114
99
}
0 commit comments