RabbitMQ服务应用是Erlang语言开发的,需要先安装Erlang
以下为安装的步骤

【Erlang】

安装weget工具

yum install wget

下载Erlang

wget --content-disposition https://packagecloud.io/rabbitmq/erlang/packages/el/7/erlang-22.3.4.12-1.el7.x86_64.rpm/download.rpm

安装Erlang

yum install erlang-22.3.4.12-1.el7.x86_64.rpm

【RabbitMQ】

下载RabbitMq

wget --content-disposition https://packagecloud.io/rabbitmq/rabbitmq-server/packages/el/7/rabbitmq-server-3.8.13-1.el7.noarch.rpm/download.rpm

安装签名

rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc

安装RabbitMq

yum install rabbitmq-server-3.8.13-1.el7.noarch.rpm

启动RabbitMq

systemctl start rabbitmq-server

开机启动RabbitMq

systemctl enable rabbitmq-server

【管理界面】

安装RabbitMq管理界面

rabbitmq-plugins enable rabbitmq_management

重启RabbitMq服务

systemctl restart rabbitmq-server

新增管理用户

rabbitmqctl add_user admin admin

给用户分配权限

rabbitmqctl set_user_tags admin administrator

【开放端口】

yum install firewalld

firewall-cmd --zone=public --add-port=15672/tcp --permanent 

systemctl start firewalld #启动
systemctl stop firewalld #停止
systemctl status firewalld #查看状态
systemctl disable firewalld #开机禁用
systemctl enable firewalld #开机启动

firewall-cmd --list-ports #查看开放端口的列表

firewall-cmd --state #查看防火墙状态

【访问管理面板】

yum install net-tools

ifconfig -a

查看当前服务器ID为:192.168.66.64

访问后台地址为:http://192.168.66.64:15672/

账号为:admin
密码为:admin

一、微服务安装
二、微服务配置
三、微服务接口设计
四、RESTful 权限
五、RESTful 速率设置
六、RESTful 注册及测试
七、状态码中文翻译

源代码:

micro-app.rar

学习Yii2微服务框架 实现一些基本功能 及案例

   'id' => 'micro-app',
    // the basePath of the application will be the `micro-app` directory
    'basePath' => __DIR__,
    // this is where the application will find all controllers
    'controllerNamespace' => 'micro\controllers',
    // set an alias to enable autoloading of classes from the 'micro' namespace
    'aliases' => [
        '@micro' => __DIR__,
    ],
    'language' => 'zh-CN',
    'components' => [
        //获取JSON数据
        'request' => [
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ]
        ],
        //配置自定义响应
        'response' => [
            'class' => 'yii\web\Response',
            'on beforeSend' => function ($event) {
                    $response = $event->sender;
                    $code = $response->getStatusCode();
                    $msg = $response->statusText;
                    if ($code == 404) {
                        !empty($response->data['message']) && $msg = $response->data['message'];
                    }
                    //设置固定返回数据参数
                    $data = [
                        'code' => $code,
                        'msg' => $msg,
                        'data' => $response->data
                    ];
                    $code == 200 && $data['data'] = $response->data;
                    $response->data = $data;
                    $response->format = yii\web\Response::FORMAT_JSON;
            },
        ],
        //会员
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
        ],
        //URL美化
        'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
               '' => 'site/index',
               ['class' => 'yii\rest\UrlRule', 'controller' => 'post','pluralize'=>false],
                
            ],
        ],
        //连接MYSQL数据库
        'db' => [
            'class' => 'yii\db\Connection',
            'dsn' => 'mysql:host=localhost;dbname=micro',
            'username' => 'root',
            'password' => 'root',
            'charset' => 'utf8',
        ],
        'cookieValidationKey' => 'O1d232trde1xww-M97_7QvwPo-5QGdkLMp#@#@', 
    ],

以下为DEMO
micro-app.zip

SELECT mobile from `fa_user` GROUP BY mobile HAVING count(*) > 1;

查询User表手机号Mobile重复值的语句

根据Yii2【高级专题】安装restful接口开发时候,发现get/delete/patch等都可以,就唯独put协议无法更新内容

https://www.yiiframework.com/doc/guide/2.0/zh-cn/tutorial-yii-as-micro-framework

比如:

PUT http://micro.com/posts/1

这里是更新id=1的内容

本实例字段内容有id、title、body

如果没有下方添加rule规则的话,就被过滤了。看效果1

14.png

二、加完代码后就解决了

15.png

原来问题出在这里
19.png