Client.php
8.2 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
namespace AliyunMNS;
use AliyunMNS\Queue;
use AliyunMNS\Config;
use AliyunMNS\Http\HttpClient;
use AliyunMNS\AsyncCallback;
use AliyunMNS\Model\AccountAttributes;
use AliyunMNS\Requests\CreateQueueRequest;
use AliyunMNS\Responses\CreateQueueResponse;
use AliyunMNS\Requests\ListQueueRequest;
use AliyunMNS\Responses\ListQueueResponse;
use AliyunMNS\Requests\DeleteQueueRequest;
use AliyunMNS\Responses\DeleteQueueResponse;
use AliyunMNS\Requests\CreateTopicRequest;
use AliyunMNS\Responses\CreateTopicResponse;
use AliyunMNS\Requests\DeleteTopicRequest;
use AliyunMNS\Responses\DeleteTopicResponse;
use AliyunMNS\Requests\ListTopicRequest;
use AliyunMNS\Responses\ListTopicResponse;
use AliyunMNS\Requests\GetAccountAttributesRequest;
use AliyunMNS\Responses\GetAccountAttributesResponse;
use AliyunMNS\Requests\SetAccountAttributesRequest;
use AliyunMNS\Responses\SetAccountAttributesResponse;
/**
* Please refer to
* https://docs.aliyun.com/?spm=#/pub/mns/api_reference/api_spec&queue_operation
* for more details
*/
class Client
{
private $client;
/**
* Please refer to http://www.aliyun.com/product/mns for more details
*
* @param endPoint: the host url
* could be "http://$accountId.mns.cn-hangzhou.aliyuncs.com"
* accountId could be found in aliyun.com
* @param accessId: accessId from aliyun.com
* @param accessKey: accessKey from aliyun.com
* @param securityToken: securityToken from aliyun.com
* @param config: necessary configs
*/
public function __construct($endPoint, $accessId,
$accessKey, $securityToken = NULL, Config $config = NULL)
{
$this->client = new HttpClient($endPoint, $accessId,
$accessKey, $securityToken, $config);
}
/**
* Returns a queue reference for operating on the queue
* this function does not create the queue automatically.
*
* @param string $queueName: the queue name
* @param bool $base64: whether the message in queue will be base64 encoded
*
* @return Queue $queue: the Queue instance
*/
public function getQueueRef($queueName, $base64 = TRUE)
{
return new Queue($this->client, $queueName, $base64);
}
/**
* Create Queue and Returns the Queue reference
*
* @param CreateQueueRequest $request: the QueueName and QueueAttributes
*
* @return CreateQueueResponse $response: the CreateQueueResponse
*
* @throws QueueAlreadyExistException if queue already exists
* @throws InvalidArgumentException if any argument value is invalid
* @throws MnsException if any other exception happends
*/
public function createQueue(CreateQueueRequest $request)
{
$response = new CreateQueueResponse($request->getQueueName());
return $this->client->sendRequest($request, $response);
}
/**
* Create Queue and Returns the Queue reference
* The request will not be sent until calling MnsPromise->wait();
*
* @param CreateQueueRequest $request: the QueueName and QueueAttributes
* @param AsyncCallback $callback: the Callback when the request finishes
*
* @return MnsPromise $promise: the MnsPromise instance
*
* @throws MnsException if any exception happends
*/
public function createQueueAsync(CreateQueueRequest $request,
AsyncCallback $callback = NULL)
{
$response = new CreateQueueResponse($request->getQueueName());
return $this->client->sendRequestAsync($request, $response, $callback);
}
/**
* Query the queues created by current account
*
* @param ListQueueRequest $request: define filters for quering queues
*
* @return ListQueueResponse: the response containing queueNames
*/
public function listQueue(ListQueueRequest $request)
{
$response = new ListQueueResponse();
return $this->client->sendRequest($request, $response);
}
public function listQueueAsync(ListQueueRequest $request,
AsyncCallback $callback = NULL)
{
$response = new ListQueueResponse();
return $this->client->sendRequestAsync($request, $response, $callback);
}
/**
* Delete the specified queue
* the request will succeed even when the queue does not exist
*
* @param $queueName: the queueName
*
* @return DeleteQueueResponse
*/
public function deleteQueue($queueName)
{
$request = new DeleteQueueRequest($queueName);
$response = new DeleteQueueResponse();
return $this->client->sendRequest($request, $response);
}
public function deleteQueueAsync($queueName,
AsyncCallback $callback = NULL)
{
$request = new DeleteQueueRequest($queueName);
$response = new DeleteQueueResponse();
return $this->client->sendRequestAsync($request, $response, $callback);
}
// API for Topic
/**
* Returns a topic reference for operating on the topic
* this function does not create the topic automatically.
*
* @param string $topicName: the topic name
*
* @return Topic $topic: the Topic instance
*/
public function getTopicRef($topicName)
{
return new Topic($this->client, $topicName);
}
/**
* Create Topic and Returns the Topic reference
*
* @param CreateTopicRequest $request: the TopicName and TopicAttributes
*
* @return CreateTopicResponse $response: the CreateTopicResponse
*
* @throws TopicAlreadyExistException if topic already exists
* @throws InvalidArgumentException if any argument value is invalid
* @throws MnsException if any other exception happends
*/
public function createTopic(CreateTopicRequest $request)
{
$response = new CreateTopicResponse($request->getTopicName());
return $this->client->sendRequest($request, $response);
}
/**
* Delete the specified topic
* the request will succeed even when the topic does not exist
*
* @param $topicName: the topicName
*
* @return DeleteTopicResponse
*/
public function deleteTopic($topicName)
{
$request = new DeleteTopicRequest($topicName);
$response = new DeleteTopicResponse();
return $this->client->sendRequest($request, $response);
}
/**
* Query the topics created by current account
*
* @param ListTopicRequest $request: define filters for quering topics
*
* @return ListTopicResponse: the response containing topicNames
*/
public function listTopic(ListTopicRequest $request)
{
$response = new ListTopicResponse();
return $this->client->sendRequest($request, $response);
}
/**
* Query the AccountAttributes
*
* @return GetAccountAttributesResponse: the response containing topicNames
* @throws MnsException if any exception happends
*/
public function getAccountAttributes()
{
$request = new GetAccountAttributesRequest();
$response = new GetAccountAttributesResponse();
return $this->client->sendRequest($request, $response);
}
public function getAccountAttributesAsync(AsyncCallback $callback = NULL)
{
$request = new GetAccountAttributesRequest();
$response = new GetAccountAttributesResponse();
return $this->client->sendRequestAsync($request, $response, $callback);
}
/**
* Set the AccountAttributes
*
* @param AccountAttributes $attributes: the AccountAttributes to set
*
* @return SetAccountAttributesResponse: the response
*
* @throws MnsException if any exception happends
*/
public function setAccountAttributes(AccountAttributes $attributes)
{
$request = new SetAccountAttributesRequest($attributes);
$response = new SetAccountAttributesResponse();
return $this->client->sendRequest($request, $response);
}
public function setAccountAttributesAsync(AccountAttributes $attributes,
AsyncCallback $callback = NULL)
{
$request = new SetAccountAttributesRequest($attributes);
$response = new SetAccountAttributesResponse();
return $this->client->sendRequestAsync($request, $response, $callback);
}
}
?>