티스토리 뷰

AWS

Amazon MQ 도입기

장송송 2018. 8. 22. 09:24

1. 브로커 생성하기


2. 사용자 생성하기

- Amazon MQ 브로커 설정 가장 아래에 사용자 만들기 이용.


3. 엔트포인트 이용하기

Ver MQTT

//Server

const mqtt = require('mqtt');


const _SERVER = "";

const _USER = "";

const _PASSWORD = "";

const topic = "/REAL/topic";


const client = mqtt.connect(_SERVER, {

    username: _USER,

    password: _PASSWORD

})


client.on('connect', function() {

    client.subscribe(topic)

    client.publish(topic, 'Hello mqtt')

})


client.on('message', function(topic, message) {

    // message is Buffer

    console.log(message.toString())

    client.end()

});



//Html

<!doctype html>

<html>

<head>

    <title>test Ws mqtt.js</title>

</head>

<body>

    <script src="./browserMqtt.js"></script>

    <script>

    var _SERVER = "wss://";

    var _USER = "";

    var _PASSWORD = "";

    var topic = "/REAL/topic";


    var client = mqtt.connect(_SERVER, {

        username: _USER,

        password: _PASSWORD

    }); // you add a ws:// url here


    client.subscribe(topic)


    client.on("message", function(topic, payload) {

        console.log(topic, payload.toString());

        client.end()

    })


    client.publish(topic, "hello world!")

    </script>

</body>

</html>


4. 사용자별 권한주기

- 사용자 추가시 그룹을 설정한다

- Amazon MQ 구성페이지에서 환경 설정을 한다.

    - authorizationPlugin 을 추가한다. 아래 예제소스 참고

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<broker xmlns="http://activemq.apache.org/schema/core">

    ....

 <authorizationPlugin>

      <map>

        <authorizationMap>

          <authorizationEntries>

            <authorizationEntry admin="users" read="users" topic=".REAL.&gt;" write="users"/>

            <authorizationEntry admin="users" read="users" topic="REAL.&gt;" write="users"/>

            <authorizationEntry admin="guests" read="guests" topic="DEV.&gt;" write="guests"/>

            <authorizationEntry admin="users_auth" read="users_auth" topic="USER.&gt;" write="users_auth"/>

            <authorizationEntry admin="guests,users,users_auth" read="guests,users,users_auth" topic="ActiveMQ.Advisory.&gt;" write="guests,users,users_auth"/>

            <authorizationEntry admin="admins,users,guests,activemq-webconsole" queue="&gt;" read="admins,users,guests,activemq-webconsole" write="admins,users,guests,activemq-webconsole"/>

            <authorizationEntry admin="admins,activemq-webconsole" read="admins,activemq-webconsole" topic="&gt;" write="admins,activemq-webconsole"/>

            <authorizationEntry admin="admins,activemq-webconsole" queue="&gt;" read="admins,activemq-webconsole" write="admins,activemq-webconsole"/>

          </authorizationEntries>

        </authorizationMap>

      </map>

    </authorizationPlugin>

    ....

</broker>


'AWS' 카테고리의 다른 글

AWS S3 이용하기  (2) 2016.05.24
우리는 왜 AWS를 이용해야하는가?  (0) 2016.05.18
AWS Elasticsearch 직접 구축기  (0) 2016.04.22
AWS EC2 처음시작.  (1) 2016.04.21
잡큐 - Gearman and Lambda (2) - Lambda  (0) 2016.04.10
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/11   »
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
글 보관함