forked from cpj555/rocketmq-http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRocketMqFactory.php
More file actions
66 lines (51 loc) · 1.87 KB
/
Copy pathRocketMqFactory.php
File metadata and controls
66 lines (51 loc) · 1.87 KB
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
<?php
use Losingbattle\RocketMqHttp\Consumer;
use Losingbattle\RocketMqHttp\Contract\PackerInterface;
use Losingbattle\RocketMqHttp\Option;
use Losingbattle\RocketMqHttp\Producer;
use GuzzleHttp\Client;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Utils\ApplicationContext;
use Hyperf\Utils\Packer\JsonPacker;
use Pimple\Container;
class RocketMqFactory
{
public function getProducer()
{
$config = [];
$option = new Option();
$host = $config['host'];
$option->setAccessKeyId($config['access_key_id']);
$option->setAccessKeySecret($config['access_key_secret']);
$option->setInstanceId($config['instance_id']);
ApplicationContext::setContainer(new \Pimple\Psr11\Container(new Container([PackerInterface::class => new JsonPacker()])));
$httpClientFactory = function () use ($host) {
return new Client([
'base_uri' => $host,
]);
};
$logger = null;
return new Producer($httpClientFactory, $option, $logger);
}
public function getConsumer()
{
$config = [];
$option = new Option();
$host = $config['host'];
$option->setAccessKeyId($config['access_key_id']);
$option->setAccessKeySecret($config['access_key_secret']);
$option->setInstanceId($config['access_key_secret']);
$option->setInstanceId($config['instance_id']);
$container = ApplicationContext::setContainer(new \Pimple\Psr11\Container(new Container([
ConfigInterface::class => new Config(),
PackerInterface::class => new JsonPacker()
])));
$httpClientFactory = function () use ($host) {
return new Client([
'base_uri' => $host,
]);
};
$logger = null;
return new Consumer($container, $httpClientFactory, $option, $logger);
}
}