-
Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathAmqpTransportFactory.php
125 lines (111 loc) · 3.99 KB
/
AmqpTransportFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace Enqueue\AmqpExt\Symfony;
use Enqueue\AmqpExt\AmqpConnectionFactory;
use Enqueue\AmqpExt\AmqpContext;
use Enqueue\AmqpExt\Client\AmqpDriver;
use Enqueue\Symfony\TransportFactoryInterface;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
class AmqpTransportFactory implements TransportFactoryInterface
{
/**
* @var string
*/
private $name;
/**
* @param string $name
*/
public function __construct($name = 'amqp')
{
$this->name = $name;
}
/**
* {@inheritdoc}
*/
public function addConfiguration(ArrayNodeDefinition $builder)
{
$builder
->children()
->scalarNode('host')
->defaultValue('localhost')
->cannotBeEmpty()
->info('The host to connect too. Note: Max 1024 characters')
->end()
->scalarNode('port')
->defaultValue(5672)
->cannotBeEmpty()
->info('Port on the host.')
->end()
->scalarNode('login')
->defaultValue('guest')
->cannotBeEmpty()
->info('The login name to use. Note: Max 128 characters.')
->end()
->scalarNode('password')
->defaultValue('guest')
->cannotBeEmpty()
->info('Password. Note: Max 128 characters.')
->end()
->scalarNode('vhost')
->defaultValue('/')
->cannotBeEmpty()
->info('The virtual host on the host. Note: Max 128 characters.')
->end()
->integerNode('connect_timeout')
->min(0)
->info('Connection timeout. Note: 0 or greater seconds. May be fractional.')
->end()
->integerNode('read_timeout')
->min(0)
->info('Timeout in for income activity. Note: 0 or greater seconds. May be fractional.')
->end()
->integerNode('write_timeout')
->min(0)
->info('Timeout in for outcome activity. Note: 0 or greater seconds. May be fractional.')
->end()
->booleanNode('persisted')
->defaultFalse()
->end()
;
}
/**
* {@inheritdoc}
*/
public function createContext(ContainerBuilder $container, array $config)
{
$factory = new Definition(AmqpConnectionFactory::class);
$factory->setPublic(false);
$factory->setArguments([$config]);
$factoryId = sprintf('enqueue.transport.%s.connection_factory', $this->getName());
$container->setDefinition($factoryId, $factory);
$context = new Definition(AmqpContext::class);
$context->setFactory([new Reference($factoryId), 'createContext']);
$contextId = sprintf('enqueue.transport.%s.context', $this->getName());
$container->setDefinition($contextId, $context);
return $contextId;
}
/**
* {@inheritdoc}
*/
public function createDriver(ContainerBuilder $container, array $config)
{
$driver = new Definition(AmqpDriver::class);
$driver->setArguments([
new Reference(sprintf('enqueue.transport.%s.context', $this->getName())),
new Reference('enqueue.client.config'),
new Reference('enqueue.client.meta.queue_meta_registry'),
]);
$driverId = sprintf('enqueue.client.%s.driver', $this->getName());
$container->setDefinition($driverId, $driver);
return $driverId;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
}