123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace backend\controllers;
- use common\logic\MQMessage\Message;
- use Yii;
- class MessageController extends BaseController
- {
- /**
- * 发送消息 (接受多条)
- * @author: libingke
- */
- public function actionSend()
- {
- //oauth 验证 todo
- //获取接收参数 利用model验证或者判断
- $params = Yii::$app->request->post();
- $post = [
- 'message' => 'message 1',
- 'queue' => 'task_queue',
- ];
- try {
- $model = new Message();
- $data = $model->send($post['message'], $post['queue']);
- $result = ['code' => 200, 'message' => Yii::t('common', 'OK'), 'data' => $data];
- } catch (\common\logic\MQMessage\Exception $e) {
- $result = ['code' => $e->getCode(), 'message' => $e->getMessage(), 'data' => []];
- }
- return $result;
- }
- /**
- * 发送消息 (接受多条)
- * @author: libingke
- */
- public function actionBatchSend()
- {
- //$params = Yii::$app->request->post();
- $post = [
- 'messages' => ['message 1', 'message 2'],
- 'queue' => 'task_queue',
- ];
- try {
- $model = new Message();
- $data = $model->batchSend($post['messages'], $post['queue']);
- $result = ['code' => 200, 'message' => Yii::t('common', 'OK'), 'data' => $data];
- } catch (\common\logic\MQMessage\Exception $e) {
- $result = ['code' => $e->getCode(), 'message' => $e->getMessage(), 'data' => []];
- }
- return $result;
- }
- /**
- * 消费消息
- * @author: libingke
- */
- public function actionReceive()
- {
- //$params = Yii::$app->request->post();
- $post = [
- 'message' => 'message 1',
- 'queue' => 'task_queue',
- ];
- try {
- $model = new Message();
- $data = $model->receive($post['queue'], $post['message']);
- $result = ['code' => 200, 'message' => Yii::t('common', 'OK'), 'data' => $data];
- } catch (\common\logic\MQMessage\Exception $e) {
- $result = ['code' => $e->getCode(), 'message' => $e->getMessage(), 'data' => []];
- }
- return $result;
- }
- /**
- * 批量消费消息
- * @author: libingke
- */
- public function actionBatchReceive()
- {
- //$params = Yii::$app->request->post();
- $post = [
- 'messages' => ['message 1', 'message 2'],
- 'queue' => 'task_queue',
- ];
- try {
- $model = new Message();
- $data = $model->batchReceive($post['queue'], $post['messages']);
- $result = ['code' => 200, 'message' => Yii::t('common', 'OK'), 'data' => $data];
- } catch (\common\logic\MQMessage\Exception $e) {
- $result = ['code' => $e->getCode(), 'message' => $e->getMessage(), 'data' => []];
- }
- return $result;
- }
- /**
- * 删除消息
- * @author: libingke
- */
- public function actionDelete()
- {
- }
- /**
- * 批量删除消息
- * @author: libingke
- */
- public function actionBatchDelete()
- {
- }
- }
|