JP2019176275A - Communication method, communication system, communication apparatus, and computer program - Google Patents

Communication method, communication system, communication apparatus, and computer program Download PDF

Info

Publication number
JP2019176275A
JP2019176275A JP2018060853A JP2018060853A JP2019176275A JP 2019176275 A JP2019176275 A JP 2019176275A JP 2018060853 A JP2018060853 A JP 2018060853A JP 2018060853 A JP2018060853 A JP 2018060853A JP 2019176275 A JP2019176275 A JP 2019176275A
Authority
JP
Japan
Prior art keywords
message
server
server device
client device
client
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
JP2018060853A
Other languages
Japanese (ja)
Other versions
JP6857151B2 (en
Inventor
近藤 貴俊
Takatoshi Kondo
貴俊 近藤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ogis Ri Co Ltd
Original Assignee
Ogis Ri Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ogis Ri Co Ltd filed Critical Ogis Ri Co Ltd
Priority to JP2018060853A priority Critical patent/JP6857151B2/en
Publication of JP2019176275A publication Critical patent/JP2019176275A/en
Application granted granted Critical
Publication of JP6857151B2 publication Critical patent/JP6857151B2/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

To provide a communication method, a communication system, a communication apparatus, and a computer program, which achieve flexibly a delivery warrant of a message.SOLUTION: In a publish/subscribe type communication method, a server device as a broker receives a message on selection of a delivery assurance attribution indicating that the message is delivered with any one of a 0th delivery assurance that should deliver one time at a maximum, a 1st delivery assurance that should deliver one time at least, and a 2nd delivery assurance that must deliver one time to a client device as a subscriber in each message. Even if it becomes a processing impossible state itself, the server device receives the selection of an operation assurance attribution whether the delivery of the message should be assured, and switches a reception processing in response to the message received from the client device or the other server device in accordance with a combination of the selection of the delivery assurance attribution and the selection of the operation assurance.SELECTED DRAWING: Figure 1

Description

本開示は、パブリッシュ/サブスクライブ型のメッセージの送受信における到達保証を達成する通信方法、通信システム、通信装置及びコンピュータプログラムに関する。   The present disclosure relates to a communication method, a communication system, a communication apparatus, and a computer program for achieving arrival guarantee in transmission / reception of a publish / subscribe type message.

簡素な構成で更に通信量が少なくて済むパブリッシュ(Publish )/サブクライブ(Subscribe )型(以下、Pub/Sub 型という)のメッセージ送受信システムが、IoT(Internet of Things )システム等の種々の分野で利用されている。Pub/Sub 型のメッセージ送受信では、メッセージ(データ)の送信者であるパブリッシャ(publisher )と、メッセージの受信者であるサブスクライバ(subscriber)との間のメッセージの送受信をブローカ(broker)と呼ばれるサーバが仲介する。そしてそのメッセージ送受信の仲介には、トピックと呼ばれるメッセージの送信先を区別するための情報が利用される。まずサブスクライバがトピックを指定し、該トピックを送信先とするメッセージを講読する。この講読という処理によりブローカではサブスクライバの識別情報とトピックの識別情報とが対応付けられる。パブリッシャがトピックを指定してメッセージを送信した場合、ブローカはこれを指定されたトピックに対応するサブスクライバへ配信する。これによりパブリッシャは宛先(サブスクライバ)が誰で何人いるかなどを意識することなくメッセージを送信することができる。Pub/Sub 型メッセージ送受信システムは、その適用対象を鑑みれば低帯域のネットワーク上で利用される可能性が高いため、遅延及び損失を考慮する必要がある。   Publish / Subscribe (Subscribe) type message transmission / reception system with a simple configuration that requires less traffic in various fields such as IoT (Internet of Things) system It's being used. In Pub / Sub type message transmission / reception, a server called broker is used to send and receive messages between a publisher (publisher) who is the sender of messages (data) and a subscriber (subscriber) who is the recipient of messages. Mediate. In order to mediate the message transmission / reception, information for distinguishing a message transmission destination called a topic is used. First, a subscriber designates a topic and subscribes to a message with the topic as a transmission destination. By this processing called subscription, the broker associates the subscriber identification information with the topic identification information. When the publisher sends a message specifying a topic, the broker delivers it to the subscriber corresponding to the specified topic. As a result, the publisher can send a message without being aware of who and how many recipients (subscribers) are. Since the Pub / Sub type message transmission / reception system is likely to be used on a low-bandwidth network in view of its application target, it is necessary to consider delay and loss.

Pub/Sub 型メッセージ送受信システムは、パブリッシャ・ブローカ間、ブローカ・サブスクライバ間及びブローカ・ブローカ間はTCP/IPセッションを確立させた上でメッセージのやり取りを行なう。そのため、TCPレイヤにおいては受信確認パケット(ACK)を用い、受信側からのACKの有無によって送信側から再送制御を行なう。ACKによる再送によって輻輳が生じないよう、中継装置にて制御を行なう技術も提案されている(特許文献1)。このようにPub/Sub 型メッセージ送受信システムは、TCP/IP上でやり取りを行なうため、損失又は遅延により未達のメッセージは、TCPに基づくセッションが切断しない限りは、TCPレイヤにおける再送等の技術で保証される。しかしながらセッションが途切れた場合であってもメッセージが確実に相手側に到達することが望まれるケースがある。そこでPub/Sub 型メッセージ送受信システムでは、セッションの切断時の到達保証が規定されている。例えば、MQTT(MQ Telemetry Transport)モデルでは、「At most once」(最高1回、0回又は1回届く)、「At least Once 」(最低1回、1回以上届く)、「Exactly once」(正確に1回、ちょうど1回だけ届く)の3種類の保証を達成するプロトコルが用意されている(非特許文献1)。   The Pub / Sub message transmission / reception system exchanges messages after establishing a TCP / IP session between publisher / broker, between broker / subscriber, and between broker / broker. Therefore, in the TCP layer, a reception confirmation packet (ACK) is used, and retransmission control is performed from the transmission side depending on the presence or absence of ACK from the reception side. A technique has also been proposed in which control is performed by a relay device so that congestion does not occur due to retransmission by ACK (Patent Document 1). Since the Pub / Sub message transmission / reception system exchanges over TCP / IP in this way, messages that have not been reached due to loss or delay can be transmitted by techniques such as retransmission in the TCP layer unless the TCP-based session is disconnected. Guaranteed. However, there are cases where it is desired that the message reaches the other party even if the session is interrupted. Therefore, in the Pub / Sub type message transmission / reception system, arrival guarantee at the time of session disconnection is specified. For example, in the MQTT (MQ Telemetry Transport) model, “At most once” (at least once, 0 times or once), “At least Once” (at least once, at least once), “Exactly once” ( Protocols that achieve three types of guarantees (delivered exactly once, exactly once) are prepared (Non-Patent Document 1).

特開2006−287331号公報JP 2006-287331 A

IBM株式会社、"4.1. Quality of Service (QoS) レベルおよびフロー"、[online]、MQTT V3.1 プロトコル仕様(日本語)、インターネット<URL:http://public.dhe.ibm.com/software/dw/jp/websphere/wmq/mqtt31_spec/mqtt-v3r1_ja.pdf>IBM Corporation, "4.1. Quality of Service (QoS) Level and Flow", [online], MQTT V3.1 protocol specification (Japanese), Internet <URL: http://public.dhe.ibm.com/software /dw/jp/websphere/wmq/mqtt31_spec/mqtt-v3r1_en.pdf>

IoT関連技術の発展により、IoTデバイスの数は膨大化し、多様化している。これらのIoTデバイス、更にIoTデバイス以外の通信デバイスをも含むデバイス間でのメッセージを軽量且つ安全にやり取りできるネットワークインフラストラクチャの充実が望まれている。このようなネットワークインフラストラクチャには勿論、Pub/Sub 型メッセージ送受信システムが適合すると考えられる。   With the development of IoT related technology, the number of IoT devices has become enormous and diversified. There is a demand for a network infrastructure that can exchange messages between these IoT devices and devices including communication devices other than IoT devices in a lightweight and secure manner. Of course, a Pub / Sub message transmission / reception system is suitable for such network infrastructure.

Pub/Sub 型メッセージ送受信システムを安全なネットワークインフラストラクチャとして実現するためには、ブローカのインスタンスは複数存在していることが好ましい。更にブローカ自身の障害及び通信障害を考慮すれば、パブリッシャからサブスクライバへメッセージが到達するまでの通信経路は複数パターンが選択可能なネットワークであることが望ましい。この場合、パブリッシャからサブスクライバへ到達するまでにメッセージが経由するブローカの数は、必ずしも1つではなくなる。上述のMQTTモデルにおける到達保証では、パブリッシャ・ブローカ間、あるいはブローカ・サブスクライバ間の1対1のセッションにおける中途切断時のメッセージの到達は保証される。複数のブローカを経由したメッセージについて、経由する通信経路が変化した場合、ブローカがダウンした場合などを考慮した到達保証については考慮されていない。   In order to realize the Pub / Sub type message transmission / reception system as a secure network infrastructure, it is preferable that a plurality of broker instances exist. Further, considering the failure of the broker itself and the communication failure, it is desirable that the communication path from the publisher to the subscriber reaches a network in which a plurality of patterns can be selected. In this case, the number of brokers through which a message passes from the publisher to the subscriber is not necessarily one. The arrival guarantee in the above-mentioned MQTT model guarantees the arrival of a message at the time of a halfway disconnection in a one-to-one session between publishers and brokers or between brokers and subscribers. For messages that have passed through multiple brokers, there is no consideration for arrival guarantees that take into account the case where the communication path that passes through them has changed or the broker has gone down.

本発明は斯かる事情を鑑みてなされたものであり、メッセージの到達保証を柔軟に実現する通信方法、通信システム、通信装置及びコンピュータプログラムを提供することを目的とする。   The present invention has been made in view of such circumstances, and an object of the present invention is to provide a communication method, a communication system, a communication device, and a computer program that flexibly realize message arrival guarantee.

本開示の一態様に係る通信方法は、パブリッシュ/サブスクライブ型のメッセージを、パブリッシャ又はサブスクライバである複数のクライアント装置との間を仲介する1又は複数のサーバ装置が送受信する通信方法において、前記サーバ装置は、パブリッシャであるクライアント装置から受信したメッセージを、サブスクライバであるクライアント装置へ、多くとも1回到達すべきとする第0次到達保証、少なくとも1回到達すべきとする第1次到達保証、必ず1回到達すべきとする第2次到達保証のいずれで到達させるかの到達保証属性の選択をメッセージ毎に受け付け、自身が処理不可状態となった場合でもメッセージの到達を保証すべきか否かの動作保証属性の選択を受け付け、到達保証属性の選択及び動作保証の選択の組み合わせに応じて、クライアント装置又は他のサーバ装置から受信したメッセージに対する受信処理を切り替える。   The communication method according to an aspect of the present disclosure is a communication method in which one or more server devices that mediate between a plurality of client devices that are publishers or subscribers transmit and receive publish / subscribe type messages. The device receives the message received from the client device that is the publisher to reach the client device that is the subscriber at most once, the zero-order arrival guarantee that the message should reach at least once, the first-order arrival guarantee that the message should arrive at least once, Whether the arrival guarantee attribute to be reached in the secondary arrival guarantee that should be reached once is accepted for each message, and whether the arrival of the message should be guaranteed even when it becomes unprocessable The combination of the selection of the guaranteed operation attribute and the selection of the guaranteed operation attribute In response, switching the reception processing for a message received from the client device, or other server devices.

本開示の一態様に係る通信装置は、パブリッシュ/サブスクライブ型のメッセージの送受信を仲介するサーバ装置において、受信したメッセージを、サブスクライバへ多くとも1回到達すべきとする第0次到達保証、少なくとも1回到達すべきとする第1次到達保証、必ず1回到達すべきとする第2次到達保証のいずれで到達させるかの到達保証属性の選択を受け付ける第1の到達保証属性受付部と、自身が処理不可状態となった場合でもメッセージの到達を保証すべきか否かの動作保証属性の選択を受け付ける動作保証属性受付部と、到達保証属性の選択及び動作保証の選択の組み合わせに応じて、受信したメッセージに対する受信処理を切り替える受信処理切替部とを備える。   A communication apparatus according to an aspect of the present disclosure is a server apparatus that mediates transmission / reception of a publish / subscribe type message, and a zeroth arrival guarantee that a received message should reach a subscriber at least once, at least A first arrival assurance attribute accepting unit that accepts selection of an arrival guarantee attribute that is to be reached by a first arrival guarantee that should be reached once or a second arrival guarantee that should be reached once; Depending on the combination of the operation guarantee attribute accepting unit that accepts the selection of the operation guarantee attribute whether or not the arrival of the message should be guaranteed even when it becomes unprocessable, and the selection of the operation guarantee attribute and the operation guarantee selection, A reception processing switching unit that switches reception processing for the received message.

本開示の一態様に係るコンピュータプログラムは、通信部を備えるコンピュータに、パブリッシュ/サブスクライブ型のメッセージの送受信を実行させるコンピュータプログラムにおいて、前記コンピュータに、受信したメッセージを、サブスクライバへ多くとも1回到達すべきとする第0次到達保証、少なくとも1回到達すべきとする第1次到達保証、必ず1回到達すべきとする第2次到達保証のいずれで到達させるかの到達保証属性の選択を受け付ける処理、自身が処理不可状態となった場合でもメッセージの到達を保証すべきか否かの動作保証属性の選択を受け付ける処理、及び到達保証属性の選択及び動作保証の選択の組み合わせに応じて、受信したメッセージに対する受信処理を切り替える処理を実行させる。   A computer program according to an aspect of the present disclosure is a computer program that causes a computer including a communication unit to execute transmission / reception of a publish / subscribe type message, and the received message reaches the subscriber at most once. Select the arrival guarantee attribute to be reached by the 0th order arrival guarantee to be reached, the first arrival guarantee to be reached at least once, or the second arrival guarantee to be reached at least once Received depending on the combination of the process to accept, the process to accept the selection of the operation guarantee attribute whether or not the message should be guaranteed even if it is in the unprocessable state, and the selection of the guarantee guarantee attribute and the operation guarantee The process of switching the reception process for the received message is executed.

本開示の一態様に係る通信システムは、パブリッシュ/サブスクライブ型のメッセージをパブリッシャ又はサブスクライバとして送受信する複数のクライアント装置と、該複数のクライアント装置の間のメッセージの送受信を仲介する1又は複数のサーバ装置とを含む通信システムにおいて、前記サーバ装置は、パブリッシャであるクライアント装置から受信したメッセージを、サブスクライバであるクライアント装置へ、多くとも1回到達すべきとする第0次到達保証、少なくとも1回到達すべきとする第1次到達保証、必ず1回到達すべきとする第2次到達保証のいずれで到達させるかの到達保証属性の選択を受け付ける第1の到達保証属性受付部と、自身が処理不可状態となった場合でもメッセージの到達を保証すべきか否かの動作保証属性の選択を受け付ける動作保証属性受付部と、到達保証属性の選択及び動作保証の選択の組み合わせに応じて、クライアント装置又は他のサーバ装置から受信したメッセージに対する受信処理を切り替える受信処理切替部とを含み、前記クライアント装置は、通信接続するサーバ装置に対し前記動作保証属性を選択する第1選択部と、メッセージを送信又は受信する場合に、該メッセージの到達保証属性を選択する第2選択部とを備える。   A communication system according to an aspect of the present disclosure includes a plurality of client apparatuses that transmit and receive publish / subscribe messages as publishers or subscribers, and one or a plurality of servers that mediate transmission and reception of messages between the plurality of client apparatuses In a communication system including a device, the server device receives a message received from a client device that is a publisher to reach a client device that is a subscriber at least once. A first arrival guarantee attribute accepting unit that accepts selection of a arrival guarantee attribute that is to be reached by a first arrival guarantee that should be reached or a second arrival guarantee that must be reached once; Even if it becomes impossible, it is possible to guarantee the operation of whether or not message arrival should be guaranteed. An operation guarantee attribute accepting unit that accepts an attribute selection, and a reception process switching unit that switches a reception process for a message received from a client device or another server device in accordance with a combination of an arrival guarantee attribute selection and an operation guarantee selection. The client device includes: a first selection unit that selects the operation guarantee attribute with respect to a server device that communicates; and a second selection unit that selects an arrival guarantee attribute of the message when the message is transmitted or received. Is provided.

本開示によれば、多様な構成でもセッション毎のメッセージの到達保証のみならず、パブリッシャからサブスクライバまでのメッセージの到達保証を、実現される。   According to the present disclosure, not only the message arrival guarantee for each session but also the message arrival guarantee from the publisher to the subscriber can be realized even in various configurations.

本実施の形態における通信システムの概要図である。It is a schematic diagram of the communication system in this Embodiment. 通信システムを構成する各装置のハードウェア構成を示すブロック図である。It is a block diagram which shows the hardware constitutions of each apparatus which comprises a communication system. MQTTモデルにおける到達保証を示すシーケンス図である。It is a sequence diagram which shows the arrival guarantee in an MQTT model. keep接続が選択された場合のサーバ装置の処理手順の一例を示すフローチャートである。It is a flowchart which shows an example of the process sequence of the server apparatus when keep connection is selected. keep接続によるサブスクライブ状態の維持を示す説明図である。It is explanatory drawing which shows the maintenance of the subscribe state by keep connection. 装置間の接続例を示す図である。It is a figure which shows the example of a connection between apparatuses. 図6の接続状態にて装置間で送信されるメッセージの具体例を示す。The example of the message transmitted between apparatuses in the connection state of FIG. 6 is shown. 図6に対する切断状態を示す図である。It is a figure which shows the cutting state with respect to FIG. 図8に示した切断状態でパブリッシャからメッセージが送信された場合の処理の一例を示す図である。It is a figure which shows an example of a process when a message is transmitted from the publisher in the disconnection state shown in FIG. 図8に示した切断状態でパブリッシャからメッセージが送信された場合の処理の一例を示す図である。It is a figure which shows an example of a process when a message is transmitted from the publisher in the disconnection state shown in FIG. 再接続後の処理を示す。The process after reconnection is shown. QoS =1の場合の処理例を示す。An example of processing when QoS = 1 is shown. QoS =2の場合の処理例を示す。A processing example when QoS = 2 is shown. QoS =2の場合の処理例を示す。A processing example when QoS = 2 is shown. サーバ装置がセッション切断を検知した際に実行する処理手順の一例を示すフローチャートである。It is a flowchart which shows an example of the process sequence performed when a server apparatus detects session disconnection. クライアント装置がサーバ装置と切断された状態を示す図である。It is a figure which shows the state from which the client apparatus was disconnected from the server apparatus. 図16の切断状態から復帰した場合の処理手順を示す図である。It is a figure which shows the process sequence at the time of returning from the cutting | disconnection state of FIG. クライアント装置がサーバ装置と切断された他の状態の例を示す図である。It is a figure which shows the example of the other state by which the client apparatus was cut | disconnected from the server apparatus. 図18の切断状態から復帰した場合の処理手順を示す図である。It is a figure which shows the process sequence at the time of returning from the cutting | disconnection state of FIG. QoS =1におけるブローカであるサーバ装置によるメッセージ配信の処理手順の一例を示すフローチャートである。It is a flowchart which shows an example of the message delivery processing procedure by the server apparatus which is a broker in QoS = 1. 送信順序を示す説明図である。It is explanatory drawing which shows a transmission order. 送信順序の他の例を示す説明図である。It is explanatory drawing which shows the other example of a transmission order. サーバ装置及びクライアント装置の接続構成を示す図である。It is a figure which shows the connection structure of a server apparatus and a client apparatus. ブローカ間が切断された場合のサーバ装置における処理手順の一例を示すフローチャートである。It is a flowchart which shows an example of the process sequence in the server apparatus when the brokers are cut | disconnected. 図23に示した接続構成におけるブローカ間のセッションが切断された場合の処理の例を示す説明図である。It is explanatory drawing which shows the example of a process when the session between brokers in the connection structure shown in FIG. 23 is cut | disconnected. 図23に示した接続構成におけるブローカ間のセッションが切断された場合の処理の例を示す説明図である。It is explanatory drawing which shows the example of a process when the session between brokers in the connection structure shown in FIG. 23 is cut | disconnected. 図23に示した接続構成におけるブローカ間のセッションが切断された場合の処理の例を示す説明図である。It is explanatory drawing which shows the example of a process when the session between brokers in the connection structure shown in FIG. 23 is cut | disconnected. ブローカ間切断中のメッセージ処理手順の一例を示すフローチャートである。It is a flowchart which shows an example of the message processing procedure in the process of cutting | disconnection between brokers. ブローカダウンを保証するサーバ装置における送信手順の一例を示すフローチャートである。It is a flowchart which shows an example of the transmission procedure in the server apparatus which guarantees broker down. QoS =1でブローカダウンを保証する際の処理を示す図である。It is a figure which shows the process at the time of guaranteeing a broker down by QoS = 1. QoS =1でブローカダウンを保証する際の処理を示す図である。It is a figure which shows the process at the time of guaranteeing a broker down by QoS = 1. QoS =1でブローカダウンを保証する際の処理を示す図である。It is a figure which shows the process at the time of guaranteeing a broker down by QoS = 1. QoS =1でブローカダウンを保証する際の処理を示す図である。It is a figure which shows the process at the time of guaranteeing a broker down by QoS = 1. サーバ装置の起動時の処理手順の一例を示すフローチャートである。It is a flowchart which shows an example of the process sequence at the time of starting of a server apparatus. ブローカであるサーバ装置(b2)がダウンした場合の処理を示す図である。It is a figure which shows a process when the server apparatus (b2) which is a broker goes down. ブローカであるサーバ装置(b2)がダウンした場合の処理を示す図である。It is a figure which shows a process when the server apparatus (b2) which is a broker goes down. 図36に示した状態の後、サーバ装置(b2)が起動した後に行なわれる処理の例を示す図である。It is a figure which shows the example of the process performed after a server apparatus (b2) starts after the state shown in FIG. QoS =2におけるパケットID対応情報の説明図である。It is explanatory drawing of the packet ID corresponding | compatible information in QoS = 2. パケットID対応情報を用いたメッセージの処理手順の一例を示すフローチャートである。It is a flowchart which shows an example of the message processing procedure using packet ID corresponding | compatible information. パケットID対応情報の内容例を示す図である。It is a figure which shows the example of the content of packet ID corresponding | compatible information. パケットID対応情報の内容例を示す図である。It is a figure which shows the example of the content of packet ID corresponding | compatible information. パケットID対応情報の内容例を示す図である。It is a figure which shows the example of the content of packet ID corresponding | compatible information. サーバ装置(b2)におけるサブスクライバとのセッション切断検知時の処理手順の一例を示すフローチャートである。It is a flowchart which shows an example of the process sequence at the time of the session disconnection detection with the subscriber in a server apparatus (b2). ブローカ間のセッションが切断された場合の処理の例を示す説明図である。It is explanatory drawing which shows the example of a process when the session between brokers is cut | disconnected. ブローカ間のセッションが切断された場合の処理の例を示す説明図である。It is explanatory drawing which shows the example of a process when the session between brokers is cut | disconnected. ブローカ間のセッションが切断された場合の処理の例を示す説明図である。It is explanatory drawing which shows the example of a process when the session between brokers is cut | disconnected. QoS =2におけるブローカ間のセッションの再確立後のメッセージ送信処理の一例を示すフローチャートである。It is a flowchart which shows an example of the message transmission process after the re-establishment of the session between brokers in QoS = 2. QoS =2でブローカダウンを保証する際の処理を示す図である。It is a figure which shows the process at the time of guaranteeing broker down by QoS = 2.

以下、本開示の通信方法及び通信システムについてその実施の形態を示す図面に基づいて具体的に説明する。   Hereinafter, a communication method and a communication system according to the present disclosure will be specifically described with reference to the drawings illustrating embodiments thereof.

図1は、本実施の形態における通信システム100の概要図である。通信システム100は、複数のサーバ装置1と、複数のクライアント装置2とを含む。サーバ装置1及びクライアント装置2は夫々、ネットワークNを介して通信することが可能である。特に複数のサーバ装置1は相互に通信接続することが可能である。このときネットワークNに参加するサーバ装置1の数は例えば数十台である。クライアント装置2は複数のサーバ装置1の内のいずれかと通信接続(セッションを確立)することが可能である。複数のサーバ装置1はいずれも、共通するデータベース3にアクセスが可能である。データベース3はサーバ装置1内部又はサーバ装置1外部に通信媒体を介して接続可能に設けられている。複数のデータベース3は内容が同期するようにしてあり、サーバ装置1は、いずれのデータベース3から情報を取得してもよい。   FIG. 1 is a schematic diagram of a communication system 100 according to the present embodiment. The communication system 100 includes a plurality of server devices 1 and a plurality of client devices 2. The server device 1 and the client device 2 can communicate with each other via the network N. In particular, a plurality of server devices 1 can be connected to each other for communication. At this time, the number of server apparatuses 1 participating in the network N is, for example, several tens. The client device 2 can establish communication connection (establish a session) with any one of the plurality of server devices 1. All of the plurality of server devices 1 can access the common database 3. The database 3 is provided so as to be connected to the inside of the server device 1 or the outside of the server device 1 via a communication medium. The contents of the plurality of databases 3 are synchronized, and the server apparatus 1 may acquire information from any database 3.

複数のサーバ装置1は夫々サーバコンピュータであり、Pub/Sub 型メッセージ送受信システムにおけるブローカとして機能する。複数のクライアント装置2は所謂IoT機器であって、無線による通信部と、センサ又はスイッチとを含む機器である。クライアント装置2はスマートフォン等の通信端末機器であってもよい。クライアント装置2は夫々、パブリッシャ又はサブスクライバのいずれか一方若しくは両方として機能する。例えばスマートフォンであるクライアント装置2によって遠隔からスイッチ機器のクライアント装置2へ制御内容を送信して制御したり、センサ機器であるクライアント装置2からスマートフォンであるクライアント装置2へ測定結果を送信したりする。前者のパターンではスマートフォンであるクライアント装置2がパブリッシャとして、スイッチ機器であるクライアント装置2がサブスクライバとして機能し、後者のパターンではセンサ機器であるクライアント装置2がパブリッシャとして機能し、スマートフォンであるクライアント装置2がサブスクライバとして機能する。   Each of the plurality of server devices 1 is a server computer and functions as a broker in a Pub / Sub type message transmission / reception system. The plurality of client devices 2 are so-called IoT devices, and include a wireless communication unit and sensors or switches. The client device 2 may be a communication terminal device such as a smartphone. Each of the client devices 2 functions as one or both of a publisher and a subscriber. For example, the client device 2 that is a smartphone transmits control contents to the client device 2 that is a switch device from a remote location, or the measurement result is transmitted from the client device 2 that is a sensor device to the client device 2 that is a smartphone. In the former pattern, the client device 2 that is a smartphone functions as a publisher and the client device 2 that is a switch device functions as a subscriber. In the latter pattern, the client device 2 that is a sensor device functions as a publisher and the client device 2 that is a smartphone. Acts as a subscriber.

通信システム100では、複数のサーバ装置1群の利用をクライアント装置2に許可することにより、クライアント装置2から他のクライアント装置2をネットワークN経由で制御したり、多数のクライアント装置2から情報を収集することを可能としたりするサービスを実現することが可能である。ここで、スマートフォンであるクライアント装置2からスイッチ機器であるクライアント装置2を制御するに際し、これらの間を2つのサーバ装置1がブローカとして仲介する場合を考える。クライアント装置2とサーバ装置1との間、又は2つのサーバ装置1間のセッションが切断されるか、サーバ装置1が動作を停止(ダウン)したことで、制御情報を含むメッセージが損失すると、スイッチ制御が意図されたものとは異なる内容となる可能性がある。本実施の形態における通信システム100では、セッションを確立するサーバ装置1とクライアント装置2との間におけるメッセージの到達保証のみならず、複数のサーバ装置1を経由するメッセージのやり取りにおいてもサーバ装置1のダウンさえも考慮した到達保証を実現する。   In the communication system 100, by permitting the client device 2 to use a plurality of server devices 1 group, the client device 2 controls other client devices 2 via the network N, and collects information from many client devices 2. It is possible to realize a service that makes it possible. Here, when controlling the client apparatus 2 which is a switch apparatus from the client apparatus 2 which is a smart phone, the case where the two server apparatuses 1 mediate between these as a broker is considered. When a message including control information is lost because the session between the client device 2 and the server device 1 or between the two server devices 1 is disconnected or the server device 1 stops operating (down), the switch There is a possibility that the contents are different from those intended for control. In the communication system 100 according to the present embodiment, not only the message arrival guarantee between the server apparatus 1 and the client apparatus 2 establishing a session but also the exchange of messages via the plurality of server apparatuses 1 is performed. Achieves arrival guarantees that take even downs into account.

図2は、通信システム100を構成する各装置のハードウェア構成を示すブロック図である。サーバ装置1はサーバコンピュータを用いる。サーバ装置1は、ハードウェア的に1台のサーバコンピュータに対して、論理的に1つの装置として実現されるとは限らない。大抵の場合、1台のサーバコンピュータにて論理的に複数が動作する仮想マシンにより実現される。後述のクライアント装置2及びデータベース3についても同様である。ただし説明を簡易とするため、以下の説明では、サーバ装置1及びクライアント装置2は物理的に1つのコンピュータを用い、データベース3は1つの記憶装置を用いることとして説明する。   FIG. 2 is a block diagram illustrating a hardware configuration of each device constituting the communication system 100. The server device 1 uses a server computer. The server apparatus 1 is not always realized as one logical apparatus for one server computer in terms of hardware. In most cases, this is realized by a virtual machine in which a plurality of servers operate logically on one server computer. The same applies to the client device 2 and the database 3 to be described later. However, in order to simplify the description, in the following description, the server device 1 and the client device 2 are described as physically using one computer, and the database 3 is described as using one storage device.

サーバ装置1は夫々、制御部10、第1記憶部11、第2記憶部12、一時記憶部13及び通信部14を備える。制御部10はCPU(Central Processing Unit )、GPU(Graphics Processing Unit)等のプロセッサを用い、第1記憶部11に記憶されているサーバプログラム1Pに基づいた各処理を実行し、汎用サーバコンピュータをPub/Sub 型メッセージ送受信システムにおけるブローカとして機能させる。なお本実施の形態のサーバ装置1は基本的には、MQTTモデルのブローカに準拠した動作を行なう。一時記憶部13はDRAM(Dynamic Random Access Memory)等の揮発性メモリを用いて制御部10の処理により生成される情報を一時的に記憶する。   The server device 1 includes a control unit 10, a first storage unit 11, a second storage unit 12, a temporary storage unit 13, and a communication unit 14, respectively. The control unit 10 uses a processor such as a CPU (Central Processing Unit) and a GPU (Graphics Processing Unit) to execute each process based on the server program 1P stored in the first storage unit 11, and a general-purpose server computer is used as a Pub. Functions as a broker in the / Sub type message transmission / reception system. Note that the server device 1 according to the present embodiment basically operates in accordance with the MQTT model broker. The temporary storage unit 13 temporarily stores information generated by the processing of the control unit 10 using a volatile memory such as a DRAM (Dynamic Random Access Memory).

第1記憶部11は、ハードディスク又はフラッシュメモリ等の不揮発性メモリを用いる。第1記憶部11は、サーバプログラム1Pのほか、制御部10が処理の際に参照する情報を記憶する。   The first storage unit 11 uses a non-volatile memory such as a hard disk or a flash memory. In addition to the server program 1P, the first storage unit 11 stores information that the control unit 10 refers to when processing.

第2記憶部12は、第1記憶部11同様にサーバ装置1が内蔵する不揮発性メモリの一部を用いるか、又は、外部の記憶装置を用いる。第2記憶部12は、後述する通信処理においてサーバ装置1間で共有されるべきデータベース3として利用される。データベース3の内容については後述にて詳細を説明する。   Similar to the first storage unit 11, the second storage unit 12 uses a part of the nonvolatile memory built in the server device 1 or uses an external storage device. The 2nd memory | storage part 12 is utilized as the database 3 which should be shared between the server apparatuses 1 in the communication process mentioned later. Details of the contents of the database 3 will be described later.

通信部14は、ネットワークカード又は無線通信デバイスを用い、ネットワークNへの通信接続を実現する。通信部14はTCP/IPに準じた通信を行なうが、これに代替するプロトコルであっても構わない。サーバ装置1は通信部14によりネットワークNを介した通信接続を実現し、他のサーバ装置1との間で、1対1でセッションを確立し、図1に示したようなメッシュ状のネットワークを構築する。   The communication unit 14 realizes communication connection to the network N using a network card or a wireless communication device. The communication unit 14 performs communication according to TCP / IP, but may use a protocol instead of this. The server device 1 realizes communication connection via the network N by the communication unit 14, establishes a one-to-one session with another server device 1, and creates a mesh network as shown in FIG. To construct.

ネットワークNは、所謂インターネットである公衆網、通信キャリアネットワーク、及びIoTサービスを実現する事業者の事業者ネットワーク、それらへの接続拠点である基地局、アクセスポイント等を含む総称である。なおサーバ装置1はネットワークNの事業者ネットワークからネットワークNへ接続し、クライアント装置2は公衆網、通信キャリアネットワークからネットワークNに接続している。   The network N is a generic name including a public network that is a so-called Internet, a communication carrier network, a carrier network of a carrier that realizes an IoT service, a base station that is a connection base to them, an access point, and the like. The server device 1 is connected to the network N from the operator network of the network N, and the client device 2 is connected to the network N from the public network and the communication carrier network.

データベース3は上述したようにサーバ装置1の第2記憶部12を用いて実現されるか、又はサーバ装置1からは独立した外部記憶装置(ハードディスク及び記憶処理部)を用いてネットワークNに接続されている構成としてもよい。   The database 3 is realized using the second storage unit 12 of the server device 1 as described above, or connected to the network N using an external storage device (hard disk and storage processing unit) independent of the server device 1. It is good also as composition which has.

クライアント装置2は種々のコンピュータによって実現されるが、少なくとも制御部20、記憶部21、及び通信部23を備える。制御部20は、CPU、マイクロプロセッサ等及びクロックを用い、記憶部21に記憶してある端末用プログラム2Pに基づいた各処理により、汎用コンピュータをPub/Sub 型メッセージ送受信システムにおけるパブリッシャ又はブローカとして機能させる   The client device 2 is realized by various computers, but includes at least a control unit 20, a storage unit 21, and a communication unit 23. The control unit 20 functions as a publisher or broker in a Pub / Sub type message transmission / reception system by each processing based on the terminal program 2P stored in the storage unit 21 using a CPU, a microprocessor, etc. and a clock. Make

記憶部21はフラッシュメモリ等不揮発性メモリを用いる。記憶部21にはPub/Sub 型メッセージ送受信を実現するための端末用プログラム2Pが記憶されているほか、制御部20が処理の際に参照する情報を記憶する。   The storage unit 21 uses a nonvolatile memory such as a flash memory. The storage unit 21 stores a terminal program 2P for realizing Pub / Sub message transmission / reception, and stores information that the control unit 20 refers to during processing.

通信部22は、ネットワークカード又は無線通信デバイスを用い、ネットワークNへの通信接続を実現する。   The communication unit 22 implements communication connection to the network N using a network card or a wireless communication device.

通信システム100におけるメッセージの到達保証を実現する具体的方法について、以下フローチャート及び説明図を参照しながら、下記のように段階的に説明する。
1.装置間の通信における前提
(0)装置間のセッション
(1)QoS (到達保証)の基本
(2)keep接続
(3)ブローカ間のセッション
2.複数の保証レベル
(1)QoS =0(ゼロ)
(2)QoS =1、ただしブローカがダウンした場合は保証しない
(3)QoS =1、ブローカがダウンした場合も保証する
(4)QoS =2、ただしブローカがダウンした場合は保証しない
(5)QoS =2、ブローカがダウンした場合も保証する
A specific method for realizing message arrival guarantee in the communication system 100 will be described step by step with reference to flowcharts and explanatory diagrams.
1. Premises for communication between devices (0) Session between devices (1) Basics of QoS (reach guarantee) (2) Keep connection (3) Session between brokers Multiple assurance levels (1) QoS = 0 (zero)
(2) QoS = 1, but not guaranteed if the broker is down (3) QoS = 1, guaranteed even if the broker is down (4) QoS = 2, but not guaranteed if the broker is down (5) QoS = 2, guarantees if the broker goes down

[1.装置間の通信における前提]
(0)セッション
クライアント装置2とサーバ装置1、サーバ装置1とサーバ装置1の間は基本的に、互いにセッションを確立し、そのセッション内でメッセージをやり取りする。サーバ装置1は、複数のクライアント装置2及びサーバ装置1とセッションを確立することができ、そのセッション毎に通信相手を識別している(誰とのセッションかを識別する)。
[1. Premises for communication between devices]
(0) Session Basically, a session is established between the client device 2 and the server device 1, and between the server device 1 and the server device 1, and messages are exchanged within the session. The server apparatus 1 can establish a session with a plurality of client apparatuses 2 and the server apparatus 1 and identifies a communication partner for each session (identifies who the session is with).

(1)QoS (到達保証)の基本
複数のサーバ装置1は、上述したように基本的にMQTTモデルにおけるブローカに準拠している。したがってサーバ装置1は、クライアント装置2及び他のサーバ装置1との間のメッセージのやり取りについて、MQTTモデルの到達保証をベースに処理を実行する。図3は、MQTTモデルにおける到達保証を示すシーケンス図である。MQTTモデルでは、送信者からpublish メッセージとしてデータが送信され、このpublish メッセージは、トピック([topic] )、送信対象のデータ(ペイロード)([data/payload])、及び到達保証レベル([qos])を含む。到達保証レベルによっては、パケットを識別するパケットID([packet_id])を含む。なお、ここ及び以下の説明にて[]内はフィールド名の例を表わし、各々には適切な数値又は論理値が入り使用される。図3のシーケンス図では、メッセージの送信者と受信者との間のメッセージについての取決めが、QoS レベルが0(ゼロ),1,2である場合について夫々示されている。送信者は、メッセージを送信する(publish )に際し、QoS レベル(qos )を0,1,2のいずれかから指定することができる。
(1) Basics of QoS (guarantee guarantee) As described above, the plurality of server apparatuses 1 basically conform to the broker in the MQTT model. Therefore, the server device 1 executes processing for message exchange between the client device 2 and the other server device 1 based on the arrival guarantee of the MQTT model. FIG. 3 is a sequence diagram showing arrival guarantee in the MQTT model. In the MQTT model, data is sent from the sender as a publish message. The publish message contains the topic ([topic]), the data to be sent (payload) ([data / payload]), and the guarantee level ([qos] )including. Depending on the arrival guarantee level, a packet ID ([packet_id]) for identifying the packet is included. In this and the following description, [] represents an example of a field name, and an appropriate numerical value or logical value is entered and used for each. In the sequence diagram of FIG. 3, the message arrangement between the sender and the receiver of the message is shown when the QoS level is 0 (zero), 1 and 2, respectively. The sender can specify the QoS level (qos) from 0, 1, and 2 when transmitting (publish) the message.

図3Aで示すように、パブリッシャである送信者があるトピック(topic )についてデータ(data)をpublish メッセージとして送信する際に、QoS レベルとして「0(ゼロ)」を指定した場合、そのメッセージに対して受信者は、受信処理以外の処理は行なわない。これにより送信者側からは、メッセージが到達したか否かを確認することはできず、到達していない場合にもその状況を知り得ない。ただ、最新のデータをその都度送信する場合には、QoS =0で十分に足りる。   As shown in FIG. 3A, when data (data) is transmitted as a publish message for a topic (publisher) as a publisher, when “0 (zero)” is specified as the QoS level, The receiver does not perform any processing other than the reception processing. As a result, it is impossible for the sender to confirm whether the message has arrived, and the situation cannot be known even if the message has not arrived. However, when the latest data is transmitted each time, QoS = 0 is sufficient.

図3Bで示すように、パブリッシャである送信者があるトピックについてデータを送信する際にQoS として「1」を指定した場合(qos =1)、送信するパケットのパケットID(packet_id)を送信者と受信者との間のセッション内で採番して指定して送信する(図3Bではpacket_id=0x10)。この場合受信者は、パケットIDを指定してpubackというメッセージを返し、送信者側はこのpubackメッセージを受信するまで、送信したデータをパケットIDと共に保持(一時記憶)する。送信者があるトピックについてデータを送信し、その送信に対してpubackメッセージを受信する前に受信者との間でセッションが切断された場合、送信者は受信者とのセッションを再確立した後に、一時記憶しているpublish メッセージを、記憶しているパケットIDを指定して再送する。これにより、送信者は、受信者側でデータを受信した事実を知ることができ、受信者は、セッションの切断があったとしても必ずデータを受信することができる。ただしこの場合、データが受信者に到達してからセッションが切断されたか、到達する前に切断されたかを区別することができず、データを受信してからセッションが切断された場合には、同一のデータを複数回受信することになる。   As shown in FIG. 3B, when “1” is specified as QoS when transmitting data on a topic for which the sender is the publisher (qos = 1), the packet ID (packet_id) of the packet to be transmitted is set as the sender. The number is assigned and specified in the session with the receiver (packet_id = 0x10 in FIG. 3B). In this case, the receiver returns the message “puback” with the packet ID specified, and the sender side holds (temporarily stores) the transmitted data together with the packet ID until receiving this puback message. If a sender sends data about a topic and the session is disconnected with the recipient before receiving a puback message for that transmission, the sender re-establishes the session with the recipient, The temporarily stored publish message is retransmitted by specifying the stored packet ID. Thus, the sender can know the fact that the receiver has received the data, and the receiver can always receive the data even if the session is disconnected. However, in this case, it is impossible to distinguish whether the session was disconnected after the data arrived at the recipient, or whether the session was disconnected before it arrived. Will be received multiple times.

図3Cで示すように、パブリッシャである送信者があるトピックについてpublish メッセージを送信する際に、QoS として「2」を指定した場合、「1」を指定した際と同様に、送信するパケットのパケットIDを採番して使用して送信する(図3Cではpacket_id=0x11)。この場合受信者は、パケットIDを指定してpubrecメッセージを返し、同一のパケットIDを指定して送信されたデータについては以後、破棄する。したがってデータの再送を受けたとしてもこれを破棄してデータの受信を1回のみとすることができる。送信者はこのpubrecメッセージを受信するまで、送信したデータをパケットIDと共に保持し、pubrecメッセージを受信した場合には一時記憶していたデータを破棄する。破棄したデータと共に記憶していたパケットIDは新たなデータの送信に使用できるので、送信者はこれを宣言するpubrelメッセージをパケットIDと共に送信する。受信者はこのpubrelメッセージを受信したことを示すpubcomp メッセージを送信し、これによりQoS レベルが「2」のメッセージの送受信は完了する。QoS =2の場合もセッションが切断された場合、送信者は受信者とのセッションを再確立した後に、pubrecメッセージを未受信であればpublish メッセージを再送し、pubcomp メッセージを未受信であればpubrelメッセージを再送する。   As shown in FIG. 3C, when the publisher sender sends a publish message for a certain topic, when “2” is specified as QoS, the packet to be transmitted is the same as when “1” is specified. ID is numbered and used for transmission (in FIG. 3C, packet_id = 0x11). In this case, the receiver returns a pubrec message specifying the packet ID, and discards the data transmitted by specifying the same packet ID. Therefore, even if data is retransmitted, it can be discarded and data can be received only once. The sender holds the transmitted data together with the packet ID until the pubrec message is received, and discards the temporarily stored data when the pubrec message is received. Since the packet ID stored together with the discarded data can be used for transmission of new data, the sender transmits a pubrel message declaring this together with the packet ID. The receiver transmits a pubcomp message indicating that the pubrel message has been received, and transmission / reception of a message having a QoS level of “2” is completed. If the session is disconnected even when QoS = 2, the sender re-establishes the session with the receiver, then resends the publish message if no pubrec message has been received, and pubrel if no pubcomp message has been received. Resend the message.

なお図3B及び図3Cで示したメッセージのやり取りの中で、セッションが切断されるケースでは、受信者側では、送信者側からpublish メッセージ又はpubrelメッセージが送信された場合にこれらのメッセージが再送か否かに拘わらず、これに応答してpubrecメッセージ又はpubcomp メッセージを応答として送信する。受信者側では、publish メッセージ又はpubrelメッセージを受信していないのにpubrecメッセージ又はpubcomp メッセージを再送することはない。   In the case where the session is disconnected during the exchange of messages shown in FIGS. 3B and 3C, if the publish message or pubrel message is transmitted from the sender side, these messages are retransmitted on the receiver side. Regardless of this, a pubrec message or a pubcomp message is sent as a response. On the receiver side, the pubrec message or pubcomp message is not retransmitted even though the publish message or pubrel message has not been received.

なお図3Aから図3Cに示したMQTTにおける到達保証は、送信者と受信者という2つの装置間でのメッセージの到達保証の規定である。したがって、同一のトピックの同一のデータについてパブリッシャから接続対象のブローカまでのメッセージがQoS レベルとして「2」を指定して送信されたとしても、サブスクライバまでの到達がQoS レベル「2」で保証されるわけではない。これに対し本実施の形態における通信システム100では、MQTTにおける到達保証を利用しつつ、その到達保証の対象を、直接的にセッションを確立する2つの装置間のみならず、サブスクライバへ到達するまでの経路で最適化する。更には、セッションの切断のみならずブローカがダウンして一時記憶が破棄される状態となった場合も含めてメッセージの到達を保証する。これらの到達保証の実現については[2.]以降で説明する。   Note that the arrival guarantee in MQTT shown in FIGS. 3A to 3C is a provision for message arrival guarantee between two devices, a sender and a receiver. Therefore, even if a message from the publisher to the broker to be connected is transmitted with the QoS level “2” for the same data on the same topic, the arrival at the subscriber is guaranteed at the QoS level “2”. Do not mean. On the other hand, in the communication system 100 according to the present embodiment, while using the arrival guarantee in MQTT, not only the two devices that directly establish a session but also the arrival guarantee to the subscriber. Optimize by route. Furthermore, the message arrival is guaranteed not only when the session is disconnected, but also when the broker goes down and the temporary storage is discarded. For the realization of these arrival guarantees, see [2. This will be described later.

(2)keep接続
通信システム100では、サブスクライバであるクライアント装置2からサーバ装置1へのセッション確立の際には、「keep」というオプションを選択できるようにしてある。keep接続は、MQTTモデルにおける「CleanSesson 」というオプションで「false 」を選択してセッションを確立することに対応する。クライアント装置2はサーバ装置1へ通信接続をリクエストする際に「keep」オプションをtrueに指定しておけば、サーバ装置1との間のセッションが切断されたとしても、切断されている間にサーバ装置1へ到達したメッセージを後に受信することができる。
(2) Keep Connection In the communication system 100, when a session is established from the client device 2 as a subscriber to the server device 1, an option “keep” can be selected. The keep connection corresponds to establishing a session by selecting "false" with the option "CleanSesson" in the MQTT model. If the “keep” option is set to true when the client apparatus 2 requests communication connection to the server apparatus 1, even if the session with the server apparatus 1 is disconnected, the server is disconnected while disconnected. A message arriving at the device 1 can be received later.

keep接続を実現するための処理について説明しておく。図4は、keep接続が選択された場合のサーバ装置1の処理手順の一例を示すフローチャートである。サーバ装置1の制御部10は、サーバプログラム1Pに基づき、クライアント装置2からの通信接続のリクエストを検知すると以下の処理を実行する。   Processing for realizing keep connection will be described. FIG. 4 is a flowchart illustrating an example of a processing procedure of the server apparatus 1 when the keep connection is selected. When detecting a communication connection request from the client device 2 based on the server program 1P, the control unit 10 of the server device 1 executes the following processing.

制御部10は、通信接続してきたクライアント装置2のクライアントID(user_id)及び通信接続してきたクライアント装置2からの接続のオプション(「keep」オプション(keep=true又はfalse ))を一時記憶する(ステップS1)。   The control unit 10 temporarily stores the client ID (user_id) of the client apparatus 2 that has been connected for communication and the connection option (“keep” option (keep = true or false)) from the client apparatus 2 that has been connected for communication (step) S1).

制御部10はまず、クライアントIDを基に第2記憶部12のデータベースに記憶してあるセッション情報(後述のステップS8)を参照し(ステップS2)、接続してきたクライアント装置2に対応するセッション情報が新規であるか否かを判断する(ステップS3)。セッション情報がデータベースに存在せず、新規であると判断された場合(S3:YES)、制御部10はクライアントIDに対応付けて接続中であることを示す状態情報を新規に一時記憶部13に記憶し(ステップS4)、これにより新規セッションが開始される。   First, the control unit 10 refers to session information (step S8 to be described later) stored in the database of the second storage unit 12 based on the client ID (step S2), and session information corresponding to the connected client device 2 Is determined to be new (step S3). When it is determined that the session information does not exist in the database and is new (S3: YES), the control unit 10 newly stores state information indicating that the connection is being made in association with the client ID in the temporary storage unit 13. Store (step S4), thereby starting a new session.

次に制御部10は、セッションを確立しているクライアント装置2からサブスクライブ対象とするトピックの指定を到達保証レベル(QoS )の指定と共に受信すると(ステップS5)、指定されたトピック及び指定されたQoS をクライアントIDに対応付けて一時記憶部13に記憶する(ステップS6)。   Next, when receiving the designation of the topic to be subscribed from the client apparatus 2 that has established the session together with the designation of the guarantee level of arrival (QoS) (step S5), the control unit 10 receives the designated topic and the designated topic. QoS is associated with the client ID and stored in the temporary storage unit 13 (step S6).

制御部10は、対象のクライアント装置2からの通信接続の「keep」オプションがtrueであるか否かを判断し(ステップS7)、trueであると判断された場合(S7:YES)、クライアントIDとに対応付けてステップS5にて対象とされた指定トピック(文字列)及びQoS をセッション情報として第2記憶部12のデータベース3(「keep_sub」テーブル)に記憶する(ステップS8)。ステップS8において制御部10は、記憶するセッション情報が既に記憶されている情報と同一である場合、そのままとしておけばよい。   The control unit 10 determines whether or not the “keep” option of the communication connection from the target client device 2 is true (step S7), and if it is determined to be true (S7: YES), the client ID The designated topic (character string) and QoS targeted in step S5 are stored as session information in the database 3 ("keep_sub" table) of the second storage unit 12 (step S8). In step S8, if the session information to be stored is the same as the information already stored, the control unit 10 may leave it as it is.

その後制御部10は、指定トピックに対してパブリッシャからデータが送信される都度、このデータをサブスクライバであるクライアント装置2へ配信する処理を実行し(ステップS9)、該クライアント装置2とのセッションが切断されたか否かを判断する(ステップS10)。切断されていないと判断された場合(S10:NO)、制御部10は処理をステップS9へ戻し、指定トピックについての配信処理を続行する。   Thereafter, each time data is transmitted from the publisher to the specified topic, the control unit 10 executes a process of distributing this data to the client device 2 that is a subscriber (step S9), and the session with the client device 2 is disconnected. It is determined whether or not it has been done (step S10). When it is determined that it has not been disconnected (S10: NO), the control unit 10 returns the process to step S9 and continues the distribution process for the specified topic.

切断されたと判断された場合(S10:YES)、対応するクライアントIDの状態情報を消去して(ステップS11)、指定トピックの配信先をデータベースへと変更し(ステップS12)、処理を終了する。以後制御部10は、指定トピックについてのメッセージに含まれるデータ(ペイロード)については、トピックの識別情報に対応付けてデータベース3(「store 」テーブル及び「store_target」テーブル)に記憶する。   When it is determined that the connection has been disconnected (S10: YES), the status information of the corresponding client ID is deleted (step S11), the delivery destination of the designated topic is changed to the database (step S12), and the process ends. Thereafter, the control unit 10 stores the data (payload) included in the message about the specified topic in the database 3 (“store” table and “store_target” table) in association with the topic identification information.

通信接続の「keep」オプションがtrueでない(即ちfalse である)と判断された場合(S7:NO)、制御部10は、指定トピックに対してパブリッシャからデータが送信される都度に、これをサブスクライバであるクライアント装置2へ配信する処理を実行する(ステップS13)。そして制御部10は、クライアント装置2とのセッションが切断されたか否かを判断する(ステップS14)。切断されていないと判断された場合(S14:NO)、制御部10は処理をステップS13へ戻し、トピックに対する配信処理を続行する。切断されたと判断された場合(S14:YES)、対応するクライアントIDの状態情報を消去して(ステップS15)、処理を終了する。この場合、第2記憶部12のデータベースには情報の記憶がされない。   When it is determined that the “keep” option of the communication connection is not true (that is, false) (S7: NO), the control unit 10 adds this to the subscriber every time data is transmitted from the publisher to the specified topic. The process of delivering to the client device 2 is executed (step S13). And the control part 10 judges whether the session with the client apparatus 2 was cut | disconnected (step S14). If it is determined that it has not been disconnected (S14: NO), the control unit 10 returns the process to step S13, and continues the distribution process for the topic. If it is determined that it has been disconnected (S14: YES), the status information of the corresponding client ID is deleted (step S15), and the process is terminated. In this case, information is not stored in the database of the second storage unit 12.

ステップS3にてセッション情報が存在し、既存であると判断された場合(S3:NO)、対象のクライアント装置2は再接続であるから、制御部10はデータベースに同一のクライアントIDに対応付けて記憶されている指定トピックを読み出して状態情報を復元する(ステップS16)。   When the session information exists in step S3 and is determined to be existing (S3: NO), since the target client device 2 is reconnected, the control unit 10 associates the same client ID with the database. The stored specified topic is read and the state information is restored (step S16).

そして制御部10は、再接続時の「keep」オプションがtrueであるか否かを判断する(ステップS17)。trueであると判断された場合(S17:YES)、制御部10は、指定トピックについて第2記憶部12のデータベースに記憶されているデータ(ペイロード)を取り出して再接続してきたクライアント装置2へ配信する(ステップS18)。制御部10は、処理をステップS9へ進める。   Then, the control unit 10 determines whether or not the “keep” option at the time of reconnection is true (step S17). If it is determined to be true (S17: YES), the control unit 10 extracts the data (payload) stored in the database of the second storage unit 12 for the specified topic and distributes it to the client device 2 that has reconnected. (Step S18). The control unit 10 advances the process to step S9.

ステップS17にてtrueでない(false )と判断された場合(S17:NO)、第2記憶部12のデータベースに記憶されているクライアントIDと指定トピックの対応であるセッション情報を消去し(ステップS19)、処理をステップS13へ進める。   When it is determined that it is not true (false) in step S17 (S17: NO), the session information corresponding to the specified topic and the client ID stored in the database of the second storage unit 12 is deleted (step S19). Then, the process proceeds to step S13.

図5は、keep接続によるサブスクライブ状態の維持を示す説明図である。図5は、サブスクライバであるクライアント装置2からブローカのサーバ装置1への接続、切断等のイベントを図の上部から下部へ時系列に示し、各イベントによるサブスクライブ状態の変化を示している。「keep」オプションをtrueに指定して接続した場合には、その後に切断されたとしてもその期間に指定トピックに対してパブリッシャから送信されたメッセージについて、再接続後に配信を受けることができ、サブスクライバであるクライアント装置2は漏れなくメッセージを受信することができる。   FIG. 5 is an explanatory diagram showing maintenance of a subscribed state by keep connection. FIG. 5 shows events such as connection and disconnection from the client device 2 as a subscriber to the server device 1 of the broker in time series from the upper part to the lower part of the figure, and shows changes in the subscribe state due to each event. If you connect with the "keep" option set to true, messages sent from the publisher to the specified topic during that period can be delivered after reconnection, The client device 2 can receive the message without omission.

図6から図14を参照して、keep接続によるメッセージの配信処理実現の具体的方法をについて説明する。図6は、装置間の接続例を示す図である。識別情報「p1」のクライアント装置2(以下、サーバ装置1又はクライアント装置2(識別情報)と記載する)がパブリッシャとしてサーバ装置1(b1)(ブローカ)に通信接続し(セッションA)、クライアント装置2(s2)が、サブスクライバとしてサーバ装置1(b1)に通信接続(セッションB)する例を示している。サブスクライバであるクライアント装置2(s1)は、サーバ装置1へkeep接続(「keep」オプションをtrueに指定して通信接続)している。クライアント装置2(s1)からトピック「t1」が指定されると、サーバ装置1(b1)は、サブスクライバ毎に、その識別情報([user_id] )と対応付けて、指定トピック([topic] )及び指定されたQoS を含むセッション情報をデータベース3(「keep_sub」テーブル)に記憶する。図6の例では、サブスクライバであるクライアント装置2(s1)について(user_id=s1)、指定トピック(topic=t1)及び指定されたQoS ([qos] )を記憶している。   With reference to FIG. 6 to FIG. 14, a specific method for realizing message distribution processing by keep connection will be described. FIG. 6 is a diagram illustrating a connection example between apparatuses. A client device 2 with identification information “p1” (hereinafter referred to as server device 1 or client device 2 (identification information)) communicates with server device 1 (b1) (broker) as a publisher (session A), and the client device 2 (s2) shows an example in which communication connection (session B) is made to the server apparatus 1 (b1) as a subscriber. The client device 2 (s1), which is a subscriber, has a keep connection (communication connection with the “keep” option set to true) to the server device 1. When the topic “t1” is specified from the client device 2 (s1), the server device 1 (b1) is associated with the identification information ([user_id]) for each subscriber, and the specified topic ([topic]) and Session information including the designated QoS is stored in the database 3 ("keep_sub" table). In the example of FIG. 6, for the client device 2 (s1) as a subscriber, (user_id = s1), the specified topic (topic = t1) and the specified QoS ([qos]) are stored.

また図6では、クライアント装置2(s2)もサブスクライバとしてサーバ装置1(b1)に通信接続している(セッションC)。クライアント装置2(s2)は、サーバ装置1(b1)に通信接続する際に「keep」オプションをfalse (非keep)として通信接続しているので、データベース3(「keep_sub」テーブル)には対応するセッション情報が記憶されない。クライアント装置2(s2)がクライアント装置2(s1)と同様にトピック「t1」を指定した場合、以後、トピック「t1」についてパブリッシャであるクライアント装置2(p1)からpublish メッセージが送信される都度、ブローカであるサーバ装置1(b1)からはクライアント装置2(s1, s2)へ指定されたQoS でpublish メッセージが送信される。   In FIG. 6, the client device 2 (s2) is also connected to the server device 1 (b1) as a subscriber (session C). Since the client device 2 (s2) is connected to the server device 1 (b1) with the “keep” option set to false (non-keep), it corresponds to the database 3 (“keep_sub” table). Session information is not stored. When the client device 2 (s2) specifies the topic “t1” in the same manner as the client device 2 (s1), each time a publish message is transmitted from the client device 2 (p1) that is the publisher for the topic “t1”, A publish message is transmitted from the server device 1 (b1), which is the broker, to the client device 2 (s1, s2) with the designated QoS.

図7は、図6の接続状態にて装置間で送信されるメッセージの具体例を示す。パブリッシャであるクライアント装置2(p1)は例えば、「t1」というトピックについて「a 」というペイロード(data/payload)を含むpublish メッセージを、その送信の都度、QoS (1又は2)を指定して送信する。図7中[qos] にてQoS の指定値が含まれることを示している。このpublish メッセージには、セッション毎に起点側で採番されるパケットID(packet_id=0x100 )が付与されている。図7の図に示す状態ではクライアント装置2(s1)の状態情報はonlineであってトピック「t1」をサブクライブしている。サーバ装置1(b1)は、到達したメッセージのトピック「t1」を参照し、該トピックを指定しているサブスクライバであるクライアント装置2(s1)へ向けてペイロード(data/payload=a)を含むpublish メッセージを送信する。サーバ装置1(b1)からクライアント装置(s1)へのpublish メッセージのQoS は、クライアント装置2(s1)がサーバ装置1(b1)へサブスクライブ対象のトピックを指定する際に指定してセッション情報として記憶しているQoS と、パブリッシャから送信される際に指定されたQoS との内の小さい方に調停される。またサーバ装置1(b1)から送信されるメッセージのパケットに付与されているパケットID(packet_id=0x101 )は、送信者であるサーバ装置1(b1)によって採番されている。同様にしてクライアント装置2(s2)へもペイロード(data/payload=a)を含むpublish メッセージが送信されている(パケットID(packet_id=0x103)は別途採番されている)。   FIG. 7 shows a specific example of a message transmitted between apparatuses in the connection state of FIG. For example, the publisher client device 2 (p1) transmits a publish message including a payload (data / payload) of “a” for the topic “t1”, specifying QoS (1 or 2) each time it is transmitted. To do. [Qos] in FIG. 7 indicates that the specified value of QoS is included. The publish message is given a packet ID (packet_id = 0x100) that is assigned on the origin side for each session. In the state shown in FIG. 7, the state information of the client device 2 (s1) is online, and the topic “t1” is subscribed. The server device 1 (b1) refers to the topic “t1” of the arrived message, and publishes the payload (data / payload = a) toward the client device 2 (s1) that is the subscriber that specifies the topic. Send a message. The QoS of the publish message from the server device 1 (b1) to the client device (s1) is specified when the client device 2 (s1) specifies the topic to be subscribed to the server device 1 (b1) as session information. It is arbitrated to the smaller of the stored QoS and the QoS specified when sent from the publisher. Further, the packet ID (packet_id = 0x101) given to the packet of the message transmitted from the server device 1 (b1) is numbered by the server device 1 (b1) as the sender. Similarly, a publish message including a payload (data / payload = a) is transmitted to the client apparatus 2 (s2) (packet ID (packet_id = 0x103) is separately numbered).

図8は、図6に対する切断状態を示す図である。図8は、図6に示した接続状態から、クライアント装置2(s1, s2)とサーバ装置1との間のセッションB,Cが切断された状態となったことを示している。サーバ装置1では、クライアント装置2(s1)とのセッション切断を検知し、対応するセッション情報(s1)に対応するトピックについて配信先をデータベース3とすることを一時記憶している。一方でサーバ装置1は、クライアント装置2(s2)とのセッション切断を検知しても、このセッションは非keepであったので対応する状態情報(s2)を一時記憶していない。   FIG. 8 is a diagram showing a cut state with respect to FIG. FIG. 8 shows that the sessions B and C between the client device 2 (s1, s2) and the server device 1 have been disconnected from the connection state shown in FIG. The server device 1 temporarily stores that the session destination with the client device 2 (s1) is detected and the distribution destination is the database 3 for the topic corresponding to the corresponding session information (s1). On the other hand, even if the server device 1 detects the disconnection of the session with the client device 2 (s2), since the session is non-keep, the corresponding status information (s2) is not temporarily stored.

図9及び図10は、図8に示した切断状態でパブリッシャからメッセージが送信された場合の処理の一例を示す。クライアント装置2(p1)が図7同様に、「t1」というトピックについて「a 」というペイロードを含むpublish メッセージを、QoS (1又は2)を指定して送信する。図中[qos] にてQoS の指定値がメッセージに含まれることを示している。この場合、ブローカであるサーバ装置1(b1)は、識別情報「s1」のセッション情報に対応するトピック「t1」のメッセージについては配信先をデータベース3とすることを記憶しているから、データベース3(「store 」テーブル)に、トピック毎にメッセージを記憶する。このメッセージは保存メッセージとして記憶される。保存メッセージは例えば、メッセージ各々を識別する識別子([store_id])、トピック([topic] )、メッセージの内容([data/payload])を含む。保存メッセージは、ブローカでの受信時刻([TS])を含んでもよい。図9の例では、「123 」の識別子(store_id=123)が付されたトピック(topic=t1)について「a 」(data/payload=a)という内容の保存メッセージが記憶されている。   9 and 10 show an example of processing when a message is transmitted from the publisher in the disconnected state shown in FIG. Similarly to FIG. 7, the client apparatus 2 (p1) transmits a publish message including the payload “a” for the topic “t1”, specifying QoS (1 or 2). In the figure, [qos] indicates that the specified QoS value is included in the message. In this case, the server device 1 (b1), which is the broker, stores that the delivery destination is the database 3 for the message of the topic “t1” corresponding to the session information of the identification information “s1”. Store a message for each topic in the “store” table. This message is stored as a saved message. The stored message includes, for example, an identifier ([store_id]) for identifying each message, a topic ([topic]), and message content ([data / payload]). The stored message may include the reception time ([TS]) at the broker. In the example of FIG. 9, a stored message having the content “a” (data / payload = a) is stored for the topic (topic = t1) to which the identifier “123” (store_id = 123) is attached.

図10に示すようにサーバ装置1(b1)は続けて、データベース3に記憶した保存メッセージ(「store 」)の配信先の情報(配信先情報)を、配信先の装置の識別情報毎に更にデータベース3(「store_target」テーブル)に記憶する。一回のpublish の実行に対し記憶される保存メッセージ(「store 」テーブル)は1つであるが、配信先情報(「store_target」テーブル)は、保存メッセージの配信先の数分だけ存在することとなる。配信先情報は、配信先の識別情報([user_id] )、送信した際のパケットID([packet_id] )、メッセージの識別子([store_id])、送信されたか否かを示すフラグ([already_sent])、及び送信する際のQoS ([qos] )を含む。図10の例であれば、保存メッセージ(id=123)が、クライアント装置2(user_id=s1)向けに未送信である(already_sent=false)ことを示す配信先情報が記憶されている。またメッセージのパケットIDが対応付けて記憶される。図10の例では、publish メッセージの受信時に配信先とのセッションBは切断していることが分かっており、この場合パケットIDはNULL(MQTTで利用できる範囲(0x0001-0xffff)外を設定)に設定されている。そして配信先に対応付けて、QoS が記憶されている。このQoS は配信先のサブスクライバからサブスクライブ対象のトピックを指定する際に指定したQoS と、パブリッシャからメッセージが送信される際に指定されたQoS とで数値が小さい方のQoS とする。   As shown in FIG. 10, the server device 1 (b1) continues to store distribution destination information (distribution destination information) of the stored message (“store”) stored in the database 3 for each piece of identification information of the distribution destination device. Store in database 3 ("store_target" table). One save message ("store" table) is stored for one publish execution, but there are as many delivery destination information ("store_target" tables) as the number of delivery destinations of the saved message. Become. Delivery destination information includes delivery destination identification information ([user_id]), packet ID at the time of transmission ([packet_id]), message identifier ([store_id]), and flag indicating whether or not the message has been sent ([already_sent]) , And QoS at the time of transmission ([qos]). In the example of FIG. 10, distribution destination information indicating that the stored message (id = 123) has not been transmitted to the client device 2 (user_id = s1) (already_sent = false) is stored. The packet ID of the message is stored in association with it. In the example of FIG. 10, it is known that the session B with the delivery destination is disconnected when the publish message is received. In this case, the packet ID is set to NULL (outside the range (0x0001-0xffff) that can be used by MQTT). Is set. QoS is stored in association with the delivery destination. This QoS is the QoS with the smaller value between the QoS specified when the subscriber to be subscribed to specifies the topic to be subscribed to and the QoS specified when the message is sent from the publisher.

そしてサーバ装置1は、パブリッシャのクライアント装置2へ向けて、publish メッセージに対するpubackメッセージ(QoS =1)又はpubrecメッセージ(QoS =2)を返す。   Then, the server apparatus 1 returns a puback message (QoS = 1) or a pubrec message (QoS = 2) for the publish message to the client apparatus 2 of the publisher.

図11は、再接続後の処理を示す。クライアント装置2(s1)がサーバ装置1(他のサーバ装置1でもよい)と再び通信接続すると(セッションB)、データベース3に記憶してあるセッション情報(「keep_sub」テーブル)から、サーバ装置1側で指定トピック等のセッション情報を読み出して状態情報を復元する。そしてサーバ装置1は、データベース3に記憶されている配信先情報(「store_target」テーブル)からクライアント装置2(user_id=s1)向けの未送信メッセージ(already_sent=false)を検索する。クライアント装置2(s1)への「123 」という識別子が付された保存メッセージが未送信であることが参照される。サーバ装置1はデータベース3(「store 」テーブル)から識別子「123 」である保存メッセージのペイロード(data/payload=a)を読み出し、サブクライバであるクライアント装置2(s1)へpublish メッセージとして送信する。このとき、クライアント装置(s1)向けの配信先情報では、予め切断していた状態であってパケットIDが採番されていなかった(NULLである)ので、改めてパケットID(packet_id=0x102 )が採番されている。配信先情報のパケットIDも採番されたパケットIDで更新される。クライアント装置2(s2)からの再接続については、前回の接続が非keepであったので状態情報は復元されることなしに、新たなセッション(セッションC)を確立する。また、クライアント装置2(s2)からサブスクライブするトピックを指定する処理が行なわれない限り、サーバ装置1は、クライアント装置2(s2)の指定トピックを認識しない。   FIG. 11 shows processing after reconnection. When the client apparatus 2 (s1) communicates again with the server apparatus 1 (may be another server apparatus 1) (session B), the server apparatus 1 side uses the session information ("keep_sub" table) stored in the database 3 The session information such as the specified topic is read out to restore the state information. Then, the server apparatus 1 searches the transmission destination information (“store_target” table) stored in the database 3 for an unsent message (already_sent = false) for the client apparatus 2 (user_id = s1). It is referred that the stored message to which the identifier “123” is attached to the client apparatus 2 (s1) is not yet transmitted. The server device 1 reads the payload (data / payload = a) of the stored message having the identifier “123” from the database 3 (“store” table), and transmits it as a publish message to the client device 2 (s1) that is the sub-client. At this time, in the distribution destination information for the client apparatus (s1), the packet ID is not assigned (NULL) because it is disconnected in advance, and the packet ID (packet_id = 0x102) is newly obtained. It is numbered. The packet ID of the distribution destination information is also updated with the numbered packet ID. Regarding reconnection from the client device 2 (s2), since the previous connection was non-keep, the state information is not restored and a new session (session C) is established. In addition, the server device 1 does not recognize the specified topic of the client device 2 (s2) unless the process of specifying the topic to subscribe from the client device 2 (s2) is performed.

サーバ装置1(b1)は、データベース3に記憶されていた配信先情報(「store_target」)を、配信先へ送信できたことによって削除する。具体的には例えば、配信先からpubackメッセージを受信し、配信先での受信が確実に確認できた場合に配信先情報を削除する。記憶の削除タイミングはこれに限らず、適切に設計されるとよい。識別子「123 」の保存メッセージは、識別情報「s1」の配信先情報のみの配信先が対応していたので、送信済みとなる。サーバ装置1(b1)はデータベース3(「store 」テーブル)から保存メッセージを消去する。ただし指定されているQoS によって処理が異なる。図12は、QoS =1の場合の処理例を示す。データベース3の配信先情報(「store_target」テーブル)におけるクライアント装置2(s1)向けのメッセージについてQoS が「1(At least Once )」である場合、サーバ装置1(b1)は、図11に示したメッセージ(publish )の送信後、クライアント装置2(s1)からpubackメッセージが返信されたことを確認すると、データベース3(「store_target」テーブル及び「store 」テーブル)から「s1」向けの「123 」に係るレコードを消去する。   The server device 1 (b1) deletes the delivery destination information (“store_target”) stored in the database 3 when it can be transmitted to the delivery destination. Specifically, for example, a puback message is received from a distribution destination, and the distribution destination information is deleted when reception at the distribution destination is confirmed with certainty. The memory deletion timing is not limited to this, and may be appropriately designed. The stored message with the identifier “123” is already transmitted because the distribution destination of only the distribution destination information of the identification information “s1” corresponds. The server device 1 (b1) deletes the stored message from the database 3 (“store” table). However, processing differs depending on the specified QoS. FIG. 12 shows a processing example when QoS = 1. When QoS is “1 (At least Once)” for the message for the client device 2 (s1) in the distribution destination information (“store_target” table) of the database 3, the server device 1 (b1) is shown in FIG. After confirming that the puback message has been returned from the client device 2 (s1) after sending the message (publish), the database 3 ("store_target" table and "store" table) is associated with "123" for "s1" Erase the record.

図13及び図14は、QoS =2の場合の処理例を示す。データベース3に記憶されている配信先情報(「store_target」テーブル)に記憶してある情報が、「s1」向けのメッセージについてQoS が「2(Exactly once)」である場合の例である。サーバ装置1は、図11に示したpublish メッセージの送信後、クライアント装置2からpubrecメッセージが返信されたことを確認すると、図13に示すようにデータベース3の配信先情報(「store_target」テーブル)の未送信を示すフラグ(already_sent)の「false 」を「true」へ書き換え、pubrelメッセージをクライアント装置2へ送信する。配信先情報は、パケットIDは、pulish メッセージ送信時に採番された「0x102 」によって更新されている。そして図14に示すようにサーバ装置1は、pubrelメッセージに対してクライアント装置2からのpubcomp メッセージの受信を確認するとここで初めて、データベース3(「store_target」テーブル及び「store 」テーブル)からクライアント装置2(s1)向けの識別子「123 」を含む保存メッセージを消去する。サーバ装置(b1)がpubcomp メッセージを受信する前に、切断された場合、配信先情報は送信したか否かを示すフラグが送信済み(already_sent=true )を示したままデータベース3に保存されている。再確立後、サーバ装置(b1)は、再度pubrelメッセージの送信から処理を再開する。このとき配信先情報のパケットIDを参照してpubrelメッセージを送信している。後述の中途メッセージ情報による送信と重複する場合でも、パケットIDを保存しておき、再送時に利用することで、受信側で同一メッセージを棄却することができ、「Exactry once」を実現することができる。   13 and 14 show processing examples when QoS = 2. The information stored in the delivery destination information (“store_target” table) stored in the database 3 is an example in the case where the QoS is “2 (Exactly once)” for the message for “s1”. After confirming that the pubrec message has been returned from the client apparatus 2 after transmitting the publish message shown in FIG. 11, the server apparatus 1 stores the distribution destination information (“store_target” table) in the database 3 as shown in FIG. “False” of a flag (already_sent) indicating non-transmission is rewritten to “true”, and a pubrel message is transmitted to the client apparatus 2. In the distribution destination information, the packet ID is updated by “0x102” that is assigned when the pulish message is transmitted. Then, as shown in FIG. 14, when the server apparatus 1 confirms the reception of the pubcomp message from the client apparatus 2 in response to the pubrel message, it is the first time here that the server apparatus 1 retrieves the client apparatus 2 from the database 3 ("store_target" table and "store" table). The stored message including the identifier “123” for (s1) is deleted. If the server device (b1) is disconnected before receiving the pubcomp message, the delivery destination information is stored in the database 3 with a flag indicating whether or not the transmission destination information has already been transmitted (already_sent = true). . After the re-establishment, the server apparatus (b1) resumes the process from the transmission of the pubrel message again. At this time, the pubrel message is transmitted with reference to the packet ID of the distribution destination information. Even when it overlaps with transmission by midway message information, which will be described later, the same message can be rejected on the receiving side by storing the packet ID and using it at the time of retransmission, and "Exactry once" can be realized. .

図6から図14に示したように、サーバ装置1はデータベース3(「store 」テーブル及び「store_target」テーブル)に記憶する情報を利用したkeep接続を実現する動作を行なう。これにより、仲介するブローカの実体が1つである場合のセッションの切断に対するサブスクライバまでのメッセージの到達の保証は実現される。   As shown in FIGS. 6 to 14, the server apparatus 1 performs an operation of realizing keep connection using information stored in the database 3 (“store” table and “store_target” table). Thereby, the guarantee of the arrival of the message to the subscriber with respect to the disconnection of the session in the case where there is one broker agent that mediates is realized.

keep接続が選択されている場合サーバ装置1は更に、QoS =1又は=2で接続しているクライアント装置2との間で、図3に示したMQTTモデルにおける到達保証用のメッセージのやり取り中にセッションが切断されたケースを考慮した処理を行なう。   When keep connection is selected, the server apparatus 1 further exchanges messages for guaranteeing arrival in the MQTT model shown in FIG. 3 with the client apparatus 2 connected with QoS = 1 or = 2. Performs processing considering the case where the session is disconnected.

図15Aは、サーバ装置1がセッション切断を検知した際に実行する処理手順の一例を示すフローチャートである。なお図15A及び図15Bの処理手順は、図3Aから図3Cに示した送信者側であるサーバ装置1における手順である。図15Aのフローチャートに示す処理手順は、図4のフローチャートに示した処理手順の内、ステップS10の後に実行される。   FIG. 15A is a flowchart illustrating an example of a processing procedure executed when the server apparatus 1 detects session disconnection. 15A and 15B is a procedure in the server device 1 on the sender side shown in FIGS. 3A to 3C. The processing procedure shown in the flowchart of FIG. 15A is executed after step S10 in the processing procedure shown in the flowchart of FIG.

サーバ装置1の制御部10は、publish/pubrelメッセージを送信する際に詳細には、送信するメッセージをMQTT準拠のネットワークコントローラ(通信ライブラリ)の送信用ボックス(以下送信バッファ)にそのパケットを書き込む。ネットワークコントローラの動作により、送信用ボックスに書き込まれたパケットが対応するセッションの相手へのソケットに書き込まれ、送信が行なわれる。そしてネットワークコントローラの動作により、メッセージに対して応答されるべきメッセージ(puback/pubrec, pubcomp)を受信するとこの送信バッファからpublish/pubrelメッセージを消去する処理が行なわれる。   Specifically, when transmitting the publish / pubrel message, the control unit 10 of the server device 1 writes the packet to be transmitted in a transmission box (hereinafter referred to as a transmission buffer) of the MQTT-compliant network controller (communication library). By the operation of the network controller, the packet written in the transmission box is written in the socket to the counterpart of the corresponding session, and transmission is performed. When a message (puback / pubrec, pubcomp) to be responded to the message is received by the operation of the network controller, a process for deleting the publish / pubrel message from the transmission buffer is performed.

制御部10は、サブスクライバであるクライアント装置2との切断を検知すると(ステップS101)、送信バッファにメッセージが残存しているか否かを判断する(ステップS102)。残存していると判断された場合(S102:YES)、制御部10はその残存しているメッセージのパケットイメージをそのまま読み出し、データベース3(「keep_mqtt 」テーブル)に中途メッセージ情報として記憶する(ステップS103)。中途メッセージ情報は、送信先のクライアント装置2の識別情報(user_id )と、送信時刻(タイムスタンプ= [TS])と、メッセージのパケットイメージそのままとを含む。パケットイメージには、クライアント装置2へのメッセージ送信時に付与したパケットID、QoS 等が含まれている。送信バッファに残存しているメッセージは、セッションが切断(破棄)されると、対応するメッセージを受信していないにも拘わらず削除(破棄)され(ステップS104)、処理を終了する。   When detecting disconnection with the client device 2 as a subscriber (step S101), the control unit 10 determines whether or not a message remains in the transmission buffer (step S102). If it is determined that it remains (S102: YES), the control unit 10 reads the packet image of the remaining message as it is and stores it as intermediate message information in the database 3 ("keep_mqtt" table) (step S103). ). The midway message information includes the identification information (user_id) of the destination client apparatus 2, the transmission time (time stamp = [TS]), and the message packet image as it is. The packet image includes a packet ID, QoS, and the like assigned when a message is transmitted to the client device 2. When the session is disconnected (discarded), the message remaining in the transmission buffer is deleted (discarded) even though the corresponding message has not been received (step S104), and the process ends.

ステップS102にて残存していないと判断された場合(S102:NO)、制御部10は、そのまま処理を終了する。   If it is determined in step S102 that there is no remaining (S102: NO), the control unit 10 ends the process as it is.

図15Bは、サーバ装置1がセッション再開を検知した際に実行する処理手順の一例を示すフローチャートである。図15Bのフローチャートに示す処理手順は、図4のフローチャートに示した処理手順の内、ステップS18の前に実行される。   FIG. 15B is a flowchart illustrating an example of a processing procedure executed when the server apparatus 1 detects session resumption. The processing procedure shown in the flowchart of FIG. 15B is executed before step S18 in the processing procedure shown in the flowchart of FIG.

制御部10は、クライアント装置2からの通信接続を検知する(ステップS105)。制御部10は、通信接続の相手を特定して状態情報を復元しているので、中途メッセージ情報として、再接続してきたクライアント装置2(接続相手)を対象とする送信途中のメッセージがデータベース3(「keep_mqtt 」テーブル)に記憶されているか否かを判断する(ステップS106)。ステップS105にて記憶されていないと判断された場合(S106:NO)、制御部10は処理をそのまま次のステップS18へ進める。   The control unit 10 detects a communication connection from the client device 2 (step S105). Since the control unit 10 identifies the partner of the communication connection and restores the state information, as the midway message information, a message in the middle of transmission targeting the reconnected client device 2 (connection partner) is stored in the database 3 ( It is determined whether or not it is stored in the “keep_mqtt” table (step S106). If it is determined in step S105 that the data is not stored (S106: NO), the control unit 10 advances the process to the next step S18.

ステップS105で記憶されていると判断された場合(S106:YES)、制御部10は、データベース3に中途メッセージとして記憶してあった送信時のパケットイメージをそのまま、再接続してきたクライアント装置2へ送信する(ステップS107)。制御部10は、データベース3から読み出した中途メッセージを送信すると、データベース3(「keep_mqtt 」テーブル)から該当する中途メッセージの記憶を削除し(ステップS108)、再開時の再送の処理を終了する。中途メッセージの記憶の削除タイミングはこれに限らず、対応するメッセージ(puback/pubrec )を受信した場合など、適切に設計される。   When it is determined that it is stored in step S105 (S106: YES), the control unit 10 sends the packet image at the time of transmission stored as an intermediate message in the database 3 to the reconnected client device 2 as it is. Transmit (step S107). When the midway message read from the database 3 is transmitted, the control unit 10 deletes the storage of the corresponding midway message from the database 3 (“keep_mqtt” table) (step S108), and terminates the retransmission process when resuming. The timing for deleting the midway message is not limited to this, and is appropriately designed when a corresponding message (puback / pubrec) is received.

図16から図19を参照して図15A及び図15Bのフローチャートにおける処理を説明する。図16は、クライアント装置2がサーバ装置1と切断された状態を示す図である。なお図16はQoS =1に調停されている例を示す。図16に示すように、ブローカであるサーバ装置1(b1)がクライアント装置2(s1)へpublish メッセージを送信した後、pubackメッセージが返される前にセッションが切断されると(S101)、サーバ装置1(b1)の制御部10は、送信バッファにpublish メッセージが残存していると判断する(S102:YES)。したがって、サーバ装置1(b1)はデータベース3(「keep_mqtt 」テーブル)に、publish メッセージを中途メッセージとして記憶する(S103)。図16では具体的には、タイムスタンプ([TS])、クライアント装置(s1)の識別情報(s1)、publish メッセージ(topic=t1, packet_id=0x101, data/payload=a, qos=1)がそのまま記憶されている。これによりサーバ装置1(b1)では、pubackメッセージを受信していないために残存していたpublish メッセージが送信バッファから削除される(S104)。   Processing in the flowcharts of FIGS. 15A and 15B will be described with reference to FIGS. FIG. 16 is a diagram illustrating a state where the client device 2 is disconnected from the server device 1. FIG. 16 shows an example in which arbitration is performed with QoS = 1. As shown in FIG. 16, after the server device 1 (b1), which is a broker, transmits a publish message to the client device 2 (s1), the session is disconnected before the puback message is returned (S101). The control unit 10 of 1 (b1) determines that the publish message remains in the transmission buffer (S102: YES). Accordingly, the server apparatus 1 (b1) stores the publish message as an intermediate message in the database 3 (“keep_mqtt” table) (S103). In FIG. 16, specifically, the time stamp ([TS]), the identification information (s1) of the client device (s1), and the publish message (topic = t1, packet_id = 0x101, data / payload = a, qos = 1) It is memorized as it is. As a result, the server apparatus 1 (b1) deletes the remaining publish message from the transmission buffer because it has not received the puback message (S104).

図17は、図16の切断状態から復帰した場合の処理手順を示す図である。クライアント装置2(s1)が、サーバ装置1(b1)又は他のサーバ装置1に通信接続すると、サーバ装置1(b1又は他)ではこれを検知し(S105)、クライアント装置2(s1)向けのメッセージが、データベース3(「keep_mqtt 」テーブル)に中途メッセージ情報として記憶されているか否かを判断する(S106)。図16のケースでは、クライアント装置2(s1)向けのpublish メッセージが記憶されているので、通信接続先のサーバ装置1(b1)の制御部10はこれをデータベース3(「keep_mqtt 」テーブル)から読み出し、パケットID等をそのまま含むパケットとして再送する(S107)。データベース3(「keep_mqtt 」テーブル)からは一旦、中途メッセージとして記憶されていたpublish メッセージが削除される(S108)。クライアント装置2(s1)は、publish メッセージの再送を受け、pubackメッセージを送信する。pubackメッセージが送信完了された状態では、サーバ装置1側の送信バッファからも、データベース3(「keep_mqtt 」テーブル)における中途メッセージ情報からも、未送信であったメッセージが削除されて初期状態に戻る。これにより、メッセージのやり取りの途中で切断がされた場合に、サブスクライバであるクライアント装置2がいずれのサーバ装置1に再接続したとしても、その中断されていたMQTTにおける到達保証に係るメッセージのやり取りが完了する。   FIG. 17 is a diagram showing a processing procedure when returning from the cut state of FIG. When the client device 2 (s1) is connected to the server device 1 (b1) or another server device 1 for communication, the server device 1 (b1 or other) detects this (S105), and is directed to the client device 2 (s1). It is determined whether the message is stored as intermediate message information in the database 3 (“keep_mqtt” table) (S106). In the case of FIG. 16, since the publish message for the client device 2 (s1) is stored, the control unit 10 of the server device 1 (b1) as the communication connection destination reads this from the database 3 (“keep_mqtt” table). Then, the packet is retransmitted as a packet including the packet ID or the like (S107). The publish message stored as the midway message is once deleted from the database 3 (“keep_mqtt” table) (S108). The client device 2 (s1) receives the publish message and transmits a puback message. In a state where the transmission of the puback message is completed, the untransmitted message is deleted from the transmission buffer on the server device 1 side and the midway message information in the database 3 (“keep_mqtt” table), and the initial state is restored. As a result, when the client device 2 as a subscriber is reconnected to any server device 1 when the message is disconnected in the middle of the message exchange, the message exchange related to the arrival guarantee in the MQTT that has been interrupted is performed. Complete.

図18は、クライアント装置2がサーバ装置1と切断された他の状態の例を示す図である。なお図18はQoS =2に調停されている例を示す。調停後のQoS が「2」である場合(パブリッシャからのメッセージ送信時の指定及びサブスクライバからの指定がいずれも「2」)、ブローカであるサーバ装置1とサブスクライバであるクライアント装置2との間のセッションで考慮すべきメッセージのやり取りが未完了状態における切断のパターンは、符号Xで示すpubrecメッセージの受信前、及び符号Yで示すpubcompメッセージの受信前である。符号Xで示すpubrecメッセージの受信前においては、図16で示した処理同様に、サーバ装置1にて送信バッファにpublish メッセージが残存していると判断されるので(S102:YES)、データベース3(「keep_mqtt 」テーブル)に、中途メッセージ情報として、クライアント装置2(s1)向けのpublish メッセージのパケットイメージが記憶される(S103)。送信バッファからもpublish メッセージが削除される(S104)。そして符号Yで示すpubcomp メッセージの受信前においては、サーバ装置1にて送信バッファにpubrelメッセージが残存していると判断されるので(S102:YES)、データベース3(「keep_mqtt 」テーブル)に、中途メッセージ情報としてクライアント装置2(s1)向けのpubrelメッセージのパケットイメージが記憶される(S103)。   FIG. 18 is a diagram illustrating an example of another state in which the client device 2 is disconnected from the server device 1. FIG. 18 shows an example in which arbitration is performed with QoS = 2. When the QoS after the arbitration is “2” (the message transmission from the publisher and the designation from the subscriber are both “2”), between the server device 1 that is a broker and the client device 2 that is a subscriber. The disconnection pattern when the message exchange to be considered in the session is not completed is before the reception of the pubrec message indicated by the symbol X and before the reception of the pubcomp message indicated by the symbol Y. Before the pubrec message indicated by the symbol X is received, the server apparatus 1 determines that the publish message remains in the transmission buffer (S102: YES), as in the process shown in FIG. In the “keep_mqtt” table), the packet image of the publish message for the client apparatus 2 (s1) is stored as the midway message information (S103). The publish message is also deleted from the transmission buffer (S104). Before the pubcomp message indicated by the symbol Y is received, the server apparatus 1 determines that the pubrel message remains in the transmission buffer (S102: YES), so the database 3 ("keep_mqtt" table) A packet image of a pubrel message for the client device 2 (s1) is stored as message information (S103).

図19は、図18の切断状態から復帰した場合の処理手順を示す図である。この場合も、クライアント装置2(s1)がサーバ装置1(b1)又は他のサーバ装置1に通信接続すると、サーバ装置1(b1又は他)ではこれを検知し(S105)、クライアント装置2(s1)向けのメッセージがデータベース3(「keep_mqtt 」テーブル)における中途メッセージ情報に記憶されているか否かを判断する(S106)。図18の符号Xのタイミングで切断されていたところから復帰した場合には、クライアント装置2(s1)向けのpublish メッセージが中途メッセージ情報として記憶されているので、接続先のサーバ装置1(b1)の制御部10はこれをデータベース3(「keep_mqtt 」テーブル)から読み出し、パケットID等をそのまま含むパケットとして再送する(S107)。符号Yのpubrecメッセージの受信前のタイミングで切断されていたところから復帰した場合には、クライアント装置2(s1)向けのpubrelメッセージが記憶されている。サーバ装置1(b1)の制御部10はこれをデータベース3(「keep_mqtt 」テーブル)から読み出し、パケットID等をそのまま含むパケットとして再送する(S107)。これに対しクライアント装置2(s1)では、再接続した後にpublish メッセージの再送を受信した場合、これを既に受信処理している場合には破棄してpubrecメッセージを返信する。pubrelメッセージの再送を受信した場合には、pubcomp メッセージをサーバ装置1へ返信する。   FIG. 19 is a diagram showing a processing procedure when returning from the cut state of FIG. Also in this case, when the client device 2 (s1) communicates with the server device 1 (b1) or another server device 1, the server device 1 (b1 or other) detects this (S105), and the client device 2 (s1) ) Is stored in the intermediate message information in the database 3 ("keep_mqtt" table) (S106). When returning from the point where it was disconnected at the timing of the symbol X in FIG. 18, since the publish message for the client device 2 (s1) is stored as midway message information, the server device 1 (b1) of the connection destination The controller 10 reads this from the database 3 ("keep_mqtt" table) and retransmits it as a packet including the packet ID and the like as it is (S107). When returning from the point where it was disconnected at the timing before receiving the pubrec message with the code Y, the pubrel message for the client device 2 (s1) is stored. The control unit 10 of the server apparatus 1 (b1) reads this from the database 3 (“keep_mqtt” table) and retransmits it as a packet including the packet ID and the like as it is (S107). On the other hand, in the client apparatus 2 (s1), when the retransmission of the publish message is received after the reconnection, the client apparatus 2 (s1) discards the publish message and returns a pubrec message if it has already been received. When the retransmission of the pubrel message is received, the pubcomp message is returned to the server apparatus 1.

同様にして、サーバ装置1(b1)は、パブリッシャであるクライアント装置2との間のセッションがpuback/pubrecメッセージ又はpubcomp メッセージの送信を完了する前に切断された場合には、クライアント装置2(s1)向けの、データベース3(「keep_mqtt 」テーブル)における中途メッセージ情報としてこれを記憶する。パブリッシャであるクライアント装置2(s1)が再接続してきた場合、サーバ装置1(b1)の制御部10は、このデータベース3(「keep_mqtt 」テーブル)を参照して通信相手先へのメッセージが記憶されている場合にはパケットイメージをそのまま送信する。   Similarly, when the session with the client device 2 that is the publisher is disconnected before the transmission of the puback / pubrec message or the pubcomp message is completed, the server device 1 (b1) This is stored as intermediate message information in the database 3 ("keep_mqtt" table). When the client device 2 (s1) as a publisher reconnects, the control unit 10 of the server device 1 (b1) refers to the database 3 ("keep_mqtt" table) and stores a message to the communication partner. If so, the packet image is transmitted as it is.

このようにMQTTモデルの処理手続きを実行中に切断が検知された場合、データベース3(「keep_mqtt 」テーブル)にメッセージが中途メッセージ情報として記憶される。これにより、再度セッションが確立されたときにその直前の状態に復元される。仮に、サブスクライバであるクライアント装置2(s1)が異なるサーバ装置1へ通信接続を行なったとしても、データベース3(「keep_mqtt 」テーブル)に記憶されている中途メッセージ情報は各サーバ装置1で共有し同期し合うので同一の状況を復元させることが可能である。   As described above, when disconnection is detected during the processing procedure of the MQTT model, a message is stored in the database 3 (“keep_mqtt” table) as intermediate message information. As a result, when a session is established again, the state immediately before that is restored. Even if the client device 2 (s1) as a subscriber makes a communication connection to a different server device 1, the intermediate message information stored in the database 3 ("keep_mqtt" table) is shared and synchronized by each server device 1. It is possible to restore the same situation.

(3)ブローカ間の通信接続
通信システム100では、図1に示したようにブローカである複数のサーバ装置1が例えば数十台、相互にメッシュ状に通信接続する。サーバ装置1はブローカとして起動すると最初に、接続可能な他のサーバ装置1と通信接続を確立し、自身に通信接続しているクライアント装置2の情報(「connections」テーブル)を交換し、共有のデータベース3から参照して情報の同期処理を行なう。また、サーバ装置1間の接続は、いずれも上述のkeep接続で実現する。なおサーバ装置1は、自身に通信接続しているクライアント装置2が指定するトピックについて、サブクライブを実行する。実行先は、指定トピックのパブリッシャが通信接続している他のサーバ装置1である。サーバ装置1はいずれの場合もQoS を「2(Exactly once)」で指定する。サーバ装置1間のセッションが切断された場合、その間に自身に接続しているクライアント装置2が必要とするメッセージが送信されたとしても、他のサーバ装置1が保持していたものを取得して配信することが可能である。
(3) Communication Connection Between Brokers In the communication system 100, as shown in FIG. 1, a plurality of server devices 1 that are brokers are connected to each other in a mesh form, for example, several tens. When the server device 1 is started as a broker, it first establishes a communication connection with another connectable server device 1, exchanges information (“connections” table) on the client device 2 connected to itself, and shares Information synchronization processing is performed with reference to the database 3. Further, the connection between the server devices 1 is realized by the above-described keep connection. Note that the server device 1 performs subscribing on a topic specified by the client device 2 that is connected to the server device 1 by communication. The execution destination is another server device 1 to which the publisher of the specified topic is connected. In any case, the server device 1 designates QoS as “2 (Exactly once)”. When the session between the server apparatuses 1 is disconnected, even if a message required by the client apparatus 2 connected to the server apparatus 1 is transmitted in the meantime, a message held by another server apparatus 1 is acquired. It is possible to deliver.

[2.複数の保証レベル]
本実施の形態における通信システム100でサブスクライバまでのメッセージの到達保証は、全てのセッションが切断されずに安定的に維持している場合には、サーバ装置1間のkeep接続及びサーバ間におけるQoS =2の設定によって実現される。到達保証を妨げる要因は、セッションの切断、及びブローカであるサーバ装置1のダウンである。keep接続のみならず到達保証のために、後述するようにデータベース3を用いるが、データベース3のダウンについては冗長化によってこれを保証する。本実施の形態における通信システム100では、複数のブローカを経由するネットワークN上で、publish メッセージの送信時、又はサブスクライブ時に指定されたQoS レベルと、ブローカにおけるダウン時の動作選択に応じてメッセージ(データ)の到達を保証する。
[2. Multiple assurance levels]
In the communication system 100 according to the present embodiment, the message arrival guarantee to the subscribers is the keep connection between the server apparatuses 1 and the QoS between the servers when all the sessions are stably maintained without being disconnected. Realized by setting 2. The factors that hinder the arrival guarantee are the disconnection of the session and the down of the server device 1 that is a broker. As will be described later, the database 3 is used not only for the keep connection but also for guaranteeing the arrival, but the database 3 is guaranteed to be down by redundancy. In the communication system 100 according to the present embodiment, on the network N that passes through a plurality of brokers, the message (in accordance with the QoS level specified at the time of sending or subscribing to the publish message and the operation selection at the time of down in the broker ( Data) arrival.

ブローカであるサーバ装置1は、自身がダウンした場合、即ちサーバ装置1の実体がエラーにより消失、又は処理が停止することでプロセスが終了させられた場合に、それまでのメッセージ処理を保証するか否かを、起動時に選択する。サーバ装置1は、ダウンした場合にも保証する場合には、全ての処理をデータベース3に記憶することを前提とする。   Whether the server device 1 that is a broker guarantees message processing up to that time when the server device 1 is down, that is, when the entity of the server device 1 disappears due to an error or the process is terminated by stopping the processing. Select whether to start or not. The server device 1 is premised on storing all processing in the database 3 when guaranteeing even when the server device is down.

QoS はクライアント装置2が通信接続しているブローカであるサーバ装置1へpublish メッセージを送信する都度、又はサブスクライブするトピックを指定する際に選択するオプションの1つであり、サーバ装置1はこれを認識して以後の処理を実行する。なお、サブスクライバであるクライアント装置2の指定トピックについてのQoS は、サブスクライブが解除されない限り維持される。   QoS is one of the options that are selected every time a publish message is sent to the server device 1 that is a broker to which the client device 2 is communicatively connected, or when specifying a topic to subscribe to. Recognize and execute subsequent processing. Note that the QoS for the specified topic of the client device 2 as a subscriber is maintained unless the subscription is canceled.

選択に応じた処理内容を順に説明する。保証レベルは以下のようになる。
(1)QoS =0(ゼロ)
(2)QoS =1、ただしブローカがダウンした場合は保証しない
(3)QoS =1、ブローカがダウンした場合も保証する
(4)QoS =2、ただしブローカがダウンした場合は保証しない
(5)QoS =2、ブローカがダウンした場合も保証する
Processing contents according to the selection will be described in order. The assurance level is as follows.
(1) QoS = 0 (zero)
(2) QoS = 1, but not guaranteed if the broker is down (3) QoS = 1, guaranteed even if the broker is down (4) QoS = 2, but not guaranteed if the broker is down (5) QoS = 2, guarantees if the broker goes down

(1)QoS =0(ゼロ)
パブリッシャであるクライアント装置2から、QoS =0(ゼロ)でメッセージが送信される場合の該メッセージについての各装置における送信に係る処理について説明する。パブリッシャであるクライアント装置2から、QoS =0を指定してpublish メッセージが送信された場合、サーバ間のサブスクライブのQoS =2の設定、及びサブスクライバであるクライアント装置2からの指定トピックについてのQoS の指定に拘わらず、このメッセージの経路である全てのセッションにてQoS が「0(ゼロ)」に調停される。この場合、送信されたpublish メッセージに基づき、ブローカであるサーバ装置1はこのメッセージを指定トピックとしてサブクライブしているクライアント装置2又は他のサーバ装置1へ各1回送信するのみである。ブローカ間でも図3Aに示したpublish メッセージの送信のみが行なわれ、pubackメッセージ、pubrec/pubrel/pubcompメッセージのやり取りは行なわれない。
(1) QoS = 0 (zero)
A process related to transmission of each message regarding the message when the message is transmitted from the client apparatus 2 as the publisher with QoS = 0 (zero) will be described. When a publish message is sent from the client device 2 that is the publisher and QoS = 0 is specified, the setting of QoS = 2 for the subscribing between the servers and the QoS of the specified topic from the client device 2 that is the subscriber Regardless of the designation, QoS is arbitrated to “0 (zero)” in all sessions that are the route of this message. In this case, based on the transmitted publish message, the server device 1 that is a broker only transmits this message once to each of the client devices 2 or other server devices 1 that subscribe to the specified topic. Only the publish message shown in FIG. 3A is transmitted between the brokers, and the puback message and the pubrec / pubrel / pubcomp message are not exchanged.

サブスクライバであるクライアント装置2が、指定トピックについてQoS として「0(ゼロ)」を指定した場合、ブローカであるサーバ装置1から当該クライアント装置2へのメッセージのQoS は「0(ゼロ)」である。当該クライアント装置2へメッセージを送信するサーバ装置1は、該クライアント装置2が指定したトピックのpublish メッセージをパブリッシャ又は他のサーバ装置1から受信する都度、publish メッセージを該クライアント装置2へ向けて1回のみ送信して送受信処理を終了する。なおこの場合、パブリッシャであるクライアント装置2と該クライアント装置2が通信接続しているブローカとの間のメッセージの送受信、及び、ブローカ間のメッセージの送受信は、パブリッシャから指定されているQoS (1 or 2)に基づき行なわれる。   When the client device 2 as a subscriber designates “0 (zero)” as the QoS for the specified topic, the QoS of the message from the server device 1 as the broker to the client device 2 is “0 (zero)”. The server device 1 that transmits a message to the client device 2 receives the publish message of the topic designated by the client device 2 from the publisher or another server device 1 once and sends the publish message to the client device 2 once. Only transmit and finish the transmission / reception process. In this case, message transmission / reception between the client device 2 as a publisher and a broker to which the client device 2 is connected for communication, and message transmission / reception between brokers are performed by QoS (1 or Performed based on 2).

(2)QoS =1、ブローカダウン保証外の動作
ブローカがダウンした場合にメッセージの到達を保証しないという前提において、パブリッシャであるクライアント装置2から、QoS =1を指定してpublish メッセージが送信される場合の処理について説明する。なお以下の説明では、当該メッセージのトピックを指定しているサブスクライバであるクライアント装置2が、トピック指定時にQoS として「1」以上を指定している場合の当該サブスクライバまでのメッセージの到達について説明する。サーバ間のサブスクライブのQoS =2の設定、及びサブスクライバであるクライアント装置2からの指定トピックについてのQoS が「1」以上であるケースでは、それらのQoS の指定に拘わらず、このQoS =1のメッセージの経路である全てのセッションにてQoS が「1」に調停される。トピック指定時に「0(ゼロ)」を指定しているサブスクライバへのメッセージ送信は(1)で述べたようにpublish メッセージを1回送信するのみで処理が終了するので説明を省略する。
(2) QoS = 1, operation outside the broker down guarantee On the assumption that message arrival is not guaranteed when the broker goes down, the publisher device 2 sends a publish message specifying QoS = 1. The processing in the case will be described. In the following description, the message arrival to the subscriber when the client device 2 that is the subscriber that specifies the topic of the message specifies “1” or more as the QoS when the topic is specified will be described. In the case where the QoS for subscribing between servers is set to 2 and the QoS for the specified topic from the client device 2 as a subscriber is “1” or more, this QoS = 1 is set regardless of the QoS specification. QoS is arbitrated to “1” for all sessions that are message paths. Since the message transmission to the subscriber who designates “0 (zero)” at the time of specifying the topic is completed only by transmitting the publish message once as described in (1), the description is omitted.

(2.1)正常運用時
まず、QoS =1のメッセージに対する各サーバ装置1における処理の順序性について述べる。サーバ装置1は、第1記憶部11に記憶しているサーバプログラム1Pに基づき、パブリッシャであるクライアント装置2からメッセージの送信を受けた場合、指定されたQoS に応じてパブリッシャへ応答(pubackメッセージ)を返す。この応答のタイミングはMQTTモデルであれば、セッション毎に順序が守られればよい(図3参照)。これに対し通信システム100におけるサーバ装置1は、パブリッシャから送信されたpublish メッセージに基づきサブスクライバであるクライアント装置2又は他のブローカであるサーバ装置1との間のメッセージ送受信タイミングに対する順序性を持たせてパブリッシャへの応答を返す。
(2.1) Normal Operation First, the order of processing in each server device 1 for a message of QoS = 1 will be described. When the server apparatus 1 receives a message from the client apparatus 2 as the publisher based on the server program 1P stored in the first storage unit 11, the server apparatus 1 responds to the publisher according to the designated QoS (puback message). return it. If the timing of this response is an MQTT model, the order may be maintained for each session (see FIG. 3). On the other hand, the server apparatus 1 in the communication system 100 has an order for message transmission / reception timing with the client apparatus 2 as a subscriber or the server apparatus 1 as another broker based on the publish message transmitted from the publisher. Returns a response to the publisher.

図20は、ブローカであるサーバ装置1によるメッセージ配信の処理手順の一例を示すフローチャートである。なお図20のフローチャートに示す処理手順は、図4のフローチャートに示した手順の内のステップS9の詳細に対応する。   FIG. 20 is a flowchart illustrating an example of a processing procedure of message delivery by the server device 1 that is a broker. The processing procedure shown in the flowchart of FIG. 20 corresponds to the details of step S9 in the procedure shown in the flowchart of FIG.

サーバ装置1の制御部10は、パブリッシャとして通信接続を確立している1又は複数のクライアント装置2から、又は他のサーバ装置1からpublish メッセージを受信したか否かを判断する(ステップS201)。受信していないと判断された場合(S201:NО)、制御部10は処理をステップS201へ戻す。   The control unit 10 of the server apparatus 1 determines whether or not a publish message has been received from one or a plurality of client apparatuses 2 that have established a communication connection as a publisher, or from another server apparatus 1 (step S201). If it is determined that the data has not been received (S201: NO), the control unit 10 returns the process to step S201.

制御部10は、受信したと判断した場合(S201:YES)、受信したpublish メッセージのトピックを抽出し(ステップS202)、抽出されたトピックを指定してサブスクライブしている他の装置に、他のサーバ装置1が含まれているか否かを判断する(ステップS203)。   If the control unit 10 determines that it has been received (S201: YES), the control unit 10 extracts the topic of the received publish message (step S202), and designates the extracted topic as another device to which it has subscribed. It is determined whether or not the server apparatus 1 is included (step S203).

ステップS203にて他のサーバ装置1は含まれていないと判断された場合(S203:NO)、制御部10は、自身に通信接続しており、抽出されたトピックを指定しているサブスクライバであるクライアント装置2へ向けてステップS201で受信したpublish メッセージを送信する(ステップS204)。なおステップS204において制御部10は、送信先に、keep接続を選択しており且つセッションが切断中であるクライアント装置2が存在する場合には、送信先をデータベース3とする。続いて制御部10は、受信したpublish メッセージの送信元(パブリッシャ又は他のサーバ装置1)へpubackメッセージを返し(ステップS205)、publish メッセージの配信処理を終了する。ステップS204において、抽出されたトピックを指定していたサブスクライバが通信接続を切断しているなどして、データベース3に書き込む場合には、データベース3への書き込みが行なわれる。   When it is determined in step S203 that no other server device 1 is included (S203: NO), the control unit 10 is a subscriber who is connected to the communication and designates the extracted topic. The publish message received in step S201 is transmitted to the client device 2 (step S204). In step S <b> 204, the control unit 10 sets the transmission destination to the database 3 when there is a client device 2 that has selected keep connection and the session is disconnected. Subsequently, the control unit 10 returns a puback message to the transmission source (publisher or other server device 1) of the received publish message (step S205), and ends the publish message distribution process. In step S204, when writing to the database 3 because the subscriber who specified the extracted topic has disconnected the communication connection, the writing to the database 3 is performed.

他のサーバ装置1が含まれていると判断された場合(S203:YES)、制御部10は、抽出されたトピックを指定しているサブスクライバであるクライアント装置2及び他のサーバ装置1へステップS201で受信したpublish メッセージを送信する(ステップS206)。ステップS206においてもデータベース3が配信先となる場合には送信に代替してデータベース3への書き込みが行なわれる。   When it is determined that the other server device 1 is included (S203: YES), the control unit 10 proceeds to step S201 to the client device 2 and the other server device 1 that are subscribers that specify the extracted topic. The publish message received in step S206 is transmitted (step S206). Even in step S206, when the database 3 is the delivery destination, writing to the database 3 is performed instead of transmission.

制御部10は、ステップS206のpublish メッセージの送信先の内、他のサーバ装置1全てからpubackメッセージを受信したか否かを判断する(ステップS207)。実行先のサーバ装置1全てからpubackメッセージを受信しないと判断された場合(S207:NO)、制御部10は受信するまでpubackメッセージの送信は待機する。   The control unit 10 determines whether or not the puback message has been received from all the other server apparatuses 1 among the transmission destinations of the publish message in step S206 (step S207). When it is determined that the puback message is not received from all the execution destination server devices 1 (S207: NO), the control unit 10 waits until the puback message is received.

ステップS207にて実行先のサーバ装置1全てからpubackメッセージを受信したと判断された場合(S207:YES)、制御部10はステップS201で受信したメッセージの送信元のパブリッシャ又は他のサーバ装置1へpubackメッセージを返し(ステップS208)、publish メッセージの配信処理を終了する。   If it is determined in step S207 that the puback message has been received from all of the execution destination server apparatuses 1 (S207: YES), the control unit 10 sends the message received in step S201 to the publisher or other server apparatus 1 that has transmitted the message. A puback message is returned (step S208), and the publish message distribution process is terminated.

図20のフローチャートに示した手順にて注目すべきは、抽出されたトピックについてpublish メッセージを送信する際に、送信先に当該トピックをサブスクライブしている他のサーバ装置1が1又は複数存在する場合には(S203:YES)、その他のサーバ装置1全てからpubackメッセージを受信するまでは(S207:YES)、メッセージの送信元のパブリッシャ又は他のサーバ装置1へpubackメッセージを返さない点である。送信先に他のサーバ装置1が含まれない場合、ステップS205に示したように直ちにpubackメッセージを送信することと異なり、この点によって順序性が持たれる。これにより、クライアント装置2へは送信処理が完了したことが保証され、他のサーバ装置1を経由する場合でもその先のクライアント装置2への送信処理が完了したことが保証される。   It should be noted in the procedure shown in the flowchart of FIG. 20 that when transmitting a publish message for the extracted topic, there is one or more other server apparatuses 1 that subscribe to the topic at the transmission destination. In this case (S203: YES), the puback message is not returned to the publisher or other server device 1 that sent the message until the puback message is received from all the other server devices 1 (S207: YES). . When no other server device 1 is included in the transmission destination, the puback message is transmitted immediately as shown in step S205, and this provides order. As a result, it is guaranteed that the transmission process to the client apparatus 2 is completed, and even if the transmission is made via another server apparatus 1, it is guaranteed that the transmission process to the client apparatus 2 ahead is completed.

なお、他のサーバ装置1全てからpubackメッセージを受信するまでは(S207:YES)、メッセージの送信元のパブリッシャ又は他のサーバ装置1へpubackメッセージを返さないという制御については、各サーバ装置1に複数のクライアント装置2が通信接続しており、そして多数のトピックについて多数のメッセージが前後して送受信されることを鑑みると具体的には以下のように行なうことが好ましい。制御部10は、publish メッセージを受信すると、この1つのメッセージに対応するカウント数を初期化し、この1つのメッセージのトピックを指定トピックとするクライアント装置2及びサーバ装置1への送信処理を通信部14により実行し、送信処理の都度、カウント数を増大させる。そして、クライアント装置2へ送信する場合にはpublish メッセージの送信処理(ソケットへの書き込み)の完了が検知された時点で対象のカウント数を減少させ、データベース3に書き込む場合には書き込みの完了が検知された時点で対象のカウント数を減少させる。複数のクライアント装置2へのpublish メッセージを送信する場合、各々へのソケット書き込みの都度増大したカウント数は、全てのクライアント装置2への送信完了が検知されると、増大した分だけ減少している。送信先に他のサーバ装置1が含まれない場合、全てのクライアント装置2への送信完了が検知されて、カウント数が初期値となった時点で該1つのメッセージの送信元へpubackメッセージが送信される。他のサーバ装置1が含まれる場合、他のサーバ装置1への送信処理について完了した場合には、カウント数は増大したままである。他のサーバ装置1からのpubackメッセージの受信が検知できたタイミングで制御部10は、該1つのメッセージに対応するカウント数を減少させ、他のサーバ装置1全てからpubackメッセージを受信したことでカウント数が初期値になった時点で該1つのメッセージの送信元へpubackメッセージを送信する。   Until the puback message is received from all of the other server devices 1 (S207: YES), the control of not returning the puback message to the publisher or the other server device 1 that sent the message is sent to each server device 1. In consideration of the fact that a plurality of client devices 2 are connected for communication and a large number of messages are transmitted and received for a large number of topics, it is preferable to carry out the following specifically. When receiving the publish message, the control unit 10 initializes a count corresponding to the one message, and performs a transmission process to the client device 2 and the server device 1 using the topic of the one message as a designated topic. And the count is increased for each transmission process. When sending to the client device 2, the count of the target is decreased when the completion of the publish message transmission process (writing to the socket) is detected. When writing to the database 3, the completion of writing is detected. At that point, the target count is decreased. When a publish message is transmitted to a plurality of client devices 2, the number of counts increased each time a socket is written to each of the client devices 2 decreases when the transmission to all client devices 2 is detected. . When no other server apparatus 1 is included in the transmission destination, the completion of transmission to all client apparatuses 2 is detected, and the puback message is transmitted to the transmission source of the one message when the count number reaches the initial value. Is done. When the other server apparatus 1 is included, the count number remains increased when the transmission process to the other server apparatus 1 is completed. At the timing when the reception of the puback message from the other server apparatus 1 can be detected, the control unit 10 decreases the count corresponding to the one message and counts by receiving the puback message from all the other server apparatuses 1. When the number reaches the initial value, a puback message is transmitted to the transmission source of the one message.

図20のフローチャートに示した手順について具体的に説明する。図21は送信順序を示す説明図である。図21の説明図では、パブリッシャであるクライアント装置2と該パブリッシャから送信されるメッセージのトピックを指定トピックとしているサブスクライバであるクライアント装置2との間に、1つのブローカのみが介在する例を挙げて説明している。図21の説明図では各メッセージの表記に対し、その順序を示す数値を付している。数値が小さいほど時間的に先に実行されるものであり、同一のものは同時でもよいし前後を問わないことを意味している。図21に示す例では具体的には、最初((10)のタイミング)に、クライアント装置2(p1)からpublish メッセージが送信される。これに応じてサーバ装置1は、このメッセージのトピック「t1」を指定トピックとしたサブスクライバであるクライアント装置2(s1)へメッセージの送信タイミング(20)よりも後の(30)のタイミングに、クライアント装置2(p1)へpubackメッセージを返す。クライアント装置2(s1)から、pubackメッセージが返されるか否かはクライアント装置2の設計次第であって不明であるから、サーバ装置1(b1)はこれを待つことなくpubackメッセージをパブリッシャであるクライアント装置2(p1)へ返している。   The procedure shown in the flowchart of FIG. 20 will be specifically described. FIG. 21 is an explanatory diagram showing the transmission order. In the explanatory diagram of FIG. 21, an example in which only one broker is interposed between the client device 2 that is a publisher and the client device 2 that is a subscriber whose designated topic is a topic of a message transmitted from the publisher is given. Explains. In the explanatory diagram of FIG. 21, a numerical value indicating the order of each message is given. As the numerical value is smaller, the processing is executed earlier in time, meaning that the same thing may be performed simultaneously or before and after. Specifically, in the example shown in FIG. 21, a publish message is transmitted from the client device 2 (p1) first (timing (10)). In response to this, the server device 1 receives the client at the timing (30) after the message transmission timing (20) to the client device 2 (s1) which is a subscriber having the topic “t1” of the message as the designated topic. A puback message is returned to the device 2 (p1). Whether or not the puback message is returned from the client device 2 (s1) depends on the design of the client device 2 and is unknown. Therefore, the server device 1 (b1) sends the puback message to the client that is the publisher without waiting for this. Return to device 2 (p1).

また、パブリッシャであるクライアント装置2と通信接続しているサーバ装置1は、自身に他のブローカであるサーバ装置1が接続している場合、前記パブリッシャが送信するpublish メッセージのトピックを指定する他のサーバ装置1へメッセージを送信する。そして通信システム100におけるサーバ装置1は、他のサーバ装置1がpubackメッセージを返してくるのを待ってから、パブリッシャへpubackメッセージを返す。他のサーバ装置1(1又は複数)は、夫々に接続しているサブスクライバであるクライアント装置2へ向けて、対応するpublish メッセージを送信した後にpubackメッセージを返してくる。なお通信システム100においてサーバ装置1間の接続は全て、上述したようにkeep接続である。   In addition, the server device 1 that is communicatively connected to the client device 2 that is a publisher, when the server device 1 that is another broker is connected to the server device 1, designates the topic of the publish message transmitted by the publisher. A message is transmitted to the server device 1. Then, the server device 1 in the communication system 100 waits for another server device 1 to return a puback message, and then returns a puback message to the publisher. The other server apparatus 1 (s) returns a puback message after transmitting a corresponding publish message to the client apparatus 2 which is a subscriber connected to each other. Note that all connections between the server apparatuses 1 in the communication system 100 are keep connections as described above.

図22は送信順序の他の例を示す説明図である。図22の説明図では、パブリッシャであるクライアント装置2(p1)と該パブリッシャから送信されるメッセージのトピックを指定トピックとしているサブスクライバであるクライアント装置2(s1)との間に、2つのブローカが介在する例を挙げて説明している。図22の説明図では各メッセージに、順序を示す数値を付している。数値が小さいほど時間的に先に実行されるものであり、同一のものは同時でもよいし前後を問わないことを意味している。   FIG. 22 is an explanatory diagram showing another example of the transmission order. In the explanatory diagram of FIG. 22, two brokers are interposed between the client device 2 (p1) as a publisher and the client device 2 (s1) as a subscriber whose designated topic is the topic of a message transmitted from the publisher. An example is given. In the explanatory diagram of FIG. 22, each message is given a numerical value indicating the order. As the numerical value is smaller, the processing is executed earlier in time, meaning that the same thing may be performed simultaneously or before and after.

図22に示す例では具体的には、最初のタイミング(10)に、クライアント装置2(p1)からQoS =1を指定してpublish メッセージが送信される場合について説明する。サーバ装置1(b1)は、クライアント装置2(p1)から送信されたpublish メッセージを、自身に接続している他のサーバ装置1(b2及びb3)へ、(20)のタイミングで送信する。他のサーバ装置1、例えばサーバ装置1(b2)は、サーバ装置1(b1)から送信されたpublish メッセージを受信すると、そのトピック「t1」を指定トピックとしたサブスクライバであるクライアント装置2(s1)へpublish メッセージをタイミング(30)に送信してから、サーバ装置1(b1)へタイミング(40)でpubackメッセージを返す。クライアント装置2(s1)から、(40)のタイミングでpubackメッセージが返されるか否かはクライアント装置2の設計次第であって不明であるから、サーバ装置1(b2)はこれを待つことなくpubackメッセージを返している。サーバ装置1(b1)は、トピック「t1」のメッセージを送信したサーバ装置1(b2及びb3)のいずれからも(40)のタイミング前後でpubackメッセージが返されてきたか否かを判断する。サーバ装置1(b1)は、トピック「t1」についてのメッセージの送信先である全てのサーバ装置1(b2及びb3)からpubackメッセージが返されたことを確認した場合に、パブリッシャであるクライアント装置2(p1)へ、(50)のタイミングでpubackメッセージを返す。これにより、パブリッシャであるクライアント装置2(p1)は、(50)のタイミングでpubackメッセージをサーバ装置1(b1)から受信できたことで、これを指定トピックとするサブスクライバであるクライアント装置2へのpublish メッセージが到達したこと(受信確認ではない)を認識することができる。この意味で、通信システム100では、セッション毎の到達保証のみならず、サブスクライバまでのメッセージの到達をQoS =1で保証することが可能になる。   In the example shown in FIG. 22, specifically, a case where a publish message is transmitted from the client apparatus 2 (p1) with QoS = 1 specified at the first timing (10) will be described. The server apparatus 1 (b1) transmits the publish message transmitted from the client apparatus 2 (p1) to the other server apparatuses 1 (b2 and b3) connected to itself at the timing of (20). When the other server device 1, for example, the server device 1 (b2) receives the publish message transmitted from the server device 1 (b1), the client device 2 (s1) which is a subscriber having the topic “t1” as the designated topic. The publish message is transmitted to the server device 1 (b1) at timing (40), and then the puback message is returned to the server device 1 (b1). Whether or not the puback message is returned from the client device 2 (s1) at the timing of (40) depends on the design of the client device 2 and is unknown, so the server device 1 (b2) does not wait for this and puback The message is returned. The server apparatus 1 (b1) determines whether or not a puback message has been returned before or after the timing of (40) from any of the server apparatuses 1 (b2 and b3) that transmitted the message of the topic “t1”. When the server apparatus 1 (b1) confirms that the puback message has been returned from all the server apparatuses 1 (b2 and b3) that are the transmission destinations of the message about the topic “t1,” the client apparatus 2 that is the publisher A puback message is returned to (p1) at the timing of (50). As a result, the client device 2 (p1) that is the publisher has received the puback message from the server device 1 (b1) at the timing (50), so that the client device 2 that is the subscriber having this as the designated topic is notified. You can recognize that a publish message has arrived (not an acknowledgment). In this sense, the communication system 100 can guarantee not only the arrival guarantee for each session but also the arrival of the message to the subscriber with QoS = 1.

(2.2)切断発生時
ブローカがダウンした場合は保証しないという前提で、QoS =1が指定されたpublish メッセージが送信され、全てのセッションにてQoS が「1」に調停されるケースにおける切断時の処理について切断箇所毎に説明する。図23は、サーバ装置1及びクライアント装置2の接続構成を示す図である。図23は、パブリッシャであるクライアント装置2(p1)と該パブリッシャから送信されるメッセージのトピックをQoS =1で指定トピックとしているサブスクライバであるクライアント装置2(s1)との間に、2つのブローカが介在する場合の接続構成を示している。図23の接続構成では、パブリッシャであるクライアント装置2(p1)は、ブローカであるサーバ装置1(b1)に通信接続している(セッションE)。サブスクライバであるクライアント装置2(s1)はもう1つのブローカであるサーバ装置1(b2)に通信接続している(セッションF)。2つのブローカ間も通信接続されている(セッションG)。
(2.2) Disconnection Disconnection in the case where a publish message with QoS = 1 specified is sent and QoS is arbitrated to “1” in all sessions on the assumption that the broker is not guaranteed if it is down The processing at the time will be described for each cutting point. FIG. 23 is a diagram illustrating a connection configuration of the server device 1 and the client device 2. FIG. 23 shows that two brokers are connected between a client device 2 (p1) that is a publisher and a client device 2 (s1) that is a subscriber having a topic of a message transmitted from the publisher as a designated topic with QoS = 1. The connection structure in the case of interposition is shown. In the connection configuration of FIG. 23, the client device 2 (p1), which is a publisher, is communicatively connected to the server device 1 (b1), which is a broker (session E). The client device 2 (s1) that is a subscriber is connected to a server device 1 (b2) that is another broker (session F). Two brokers are also connected for communication (session G).

(2.2.1)パブリッシャ・ブローカ間
図23中のセッションEが切断された場合の到達保証について説明する。パブリッシャであるクライアント装置2から、QoS =1が指定されたpublish メッセージが送信された場合におけるパブリッシャとブローカとの間(セッションE)の通信の切断については、パブリッシャであるクライアント装置2(p1)からpublish メッセージが送信された後に切断されるケースを考える。
(2.2.1) Between Publisher and Broker A description will be given of arrival guarantee when session E in FIG. 23 is disconnected. Regarding the disconnection of communication between the publisher and the broker (session E) when a publish message specifying QoS = 1 is transmitted from the client device 2 that is the publisher, the client device 2 (p1) that is the publisher Consider a case where a publish message is disconnected after being sent.

このケースでは、パブリッシャであるクライアント装置2(p1)は、送信したpublish メッセージに対するpubackメッセージが返されるまで、そのpublish メッセージを送信バッファに一時記憶したままとする(図3)。なおサーバ装置1(b1)は、切断される前に受信したpublish メッセージについて、他のサーバ装置1(b2)へのpublish メッセージの送信を完了し、(40)のタイミングにて他のサーバ装置1(b2)からpubackメッセージを受信し、pubackメッセージを送信しようとしていた可能性がある。しかしながらサーバ装置1(b1)は、セッションEが切断されているのでこのpubackメッセージを送信できない。   In this case, the client device 2 (p1), which is a publisher, keeps the publish message temporarily stored in the transmission buffer until a puback message for the transmitted publish message is returned (FIG. 3). The server apparatus 1 (b1) completes the transmission of the publish message to the other server apparatus 1 (b2) for the publish message received before being disconnected, and the other server apparatus 1 at the timing of (40). There is a possibility that the puback message was received from (b2) and an attempt was made to send the puback message. However, the server device 1 (b1) cannot transmit this puback message because the session E is disconnected.

クライアント装置2(p1)は、ブローカであるサーバ装置1(ここではb1、他のブローカでもよい)へ通信接続のリクエストを実行する。リクエストに応じてセッションEが確立するとクライアント装置2(p1)は、送信バッファに一時記憶しているpublish メッセージを新たなセッションにおいて接続先のサーバ装置1(b1)へ送信する。接続先のサーバ装置1(b1)は、再接続してきたクライアント装置2から再送されたpublish メッセージについて、新たなpublish メッセージであるとして処理を行なう。この場合でもQoS =1の処理では問題なく到達保証が達成され、パブリッシャであるクライアント装置2(p1)ではサブスクライバであるクライアント装置2(s1)へメッセージが送信されたことを認識することができる。   The client device 2 (p1) executes a communication connection request to the server device 1 (here, b1, which may be another broker) which is a broker. When the session E is established in response to the request, the client device 2 (p1) transmits the publish message temporarily stored in the transmission buffer to the connection destination server device 1 (b1) in a new session. The connection destination server apparatus 1 (b1) processes the publish message retransmitted from the reconnected client apparatus 2 as a new publish message. Even in this case, arrival guarantee is achieved without any problem in the process of QoS = 1, and the client apparatus 2 (p1) as the publisher can recognize that the message has been transmitted to the client apparatus 2 (s1) as the subscriber.

(2.2.2)ブローカ・サブスクライバ間
図23中のセッションFが切断された場合の到達保証について説明する。セッションFが、サーバ装置1(b2)がクライアント装置2(s1)へ(30)のタイミングにてpublish メッセージを送信する前に切断された場合、keep接続の処理(図10から図12)により、再接続後にデータベース3から配信される。
(2.2.2) Between Broker and Subscriber The arrival guarantee when the session F in FIG. 23 is disconnected will be described. When the session F is disconnected before the server apparatus 1 (b2) transmits the publish message to the client apparatus 2 (s1) at the timing (30), the keep connection process (FIGS. 10 to 12) Delivered from database 3 after reconnection.

図23中のセッションFが、クライアント装置2(s1)からサーバ装置1(b2)へ(40)のタイミングにてpubackメッセージを送信する前に切断された場合、データベース3(「keep_mqtt 」テーブル)の中途メッセージ情報を参照した処理(図15から図17)により、中断されたやり取りが再開され、メッセージのやり取りが完了する。   If the session F in FIG. 23 is disconnected before sending the puback message from the client device 2 (s1) to the server device 1 (b2) at the timing of (40), the database 3 (“keep_mqtt” table) The interrupted exchange is resumed by the processing referring to the midway message information (FIGS. 15 to 17), and the message exchange is completed.

(2.2.3)ブローカ・ブローカ間
ブローカ間のセッションは上述したようにkeep接続が選択されている。図24は、ブローカ間が切断された場合のサーバ装置1における処理手順の一例を示すフローチャートである。なお図24のフローチャートに示す処理は基本的に、パブリッシャ側のサーバ装置1(即ち図3における送信者側)によって実行されるものである。サブスクライバ側のサーバ装置1の処理は、一部省略して実行される。
(2.2.3) Broker-Broker Session As described above, keep connection is selected for the session between brokers. FIG. 24 is a flowchart illustrating an example of a processing procedure in the server device 1 when the brokers are disconnected. Note that the processing shown in the flowchart of FIG. 24 is basically executed by the server device 1 on the publisher side (that is, the sender side in FIG. 3). The processing of the server device 1 on the subscriber side is executed with a part omitted.

サーバ装置1の制御部10は、他のサーバ装置1とのセッション切断を検知すると(ステップS301)、他のサーバ装置1にサブスクライバとしてkeep接続しているクライアント装置2をデータベース3(「keep_sub」テーブル)のセッション情報から抽出する(ステップS302)。   When the control unit 10 of the server apparatus 1 detects disconnection of the session with the other server apparatus 1 (step S301), the client apparatus 2 keep-connected to the other server apparatus 1 as a subscriber is stored in the database 3 ("keep_sub" table). ) From the session information (step S302).

制御部10は、抽出したクライアント装置2の状態情報を、自身に接続しているクライアント装置2として扱って一時記憶する(ステップS303)。ただしこのクライアント装置2についてはメッセージの配信先をデータベース3に設定する(keep接続後の切断状態と同様、図8参照)。そして制御部10は、図15Aのフローチャートに示した処理手順にしたがって、他のサーバ装置1(サブスクライバ側)向けのpublish メッセージが送信バッファに残存しているか否かを判断する(ステップS304)。残存していると判断された場合(S304:YES)、制御部10はこのpublish メッセージを、中途メッセージ情報としてでなく、本来であれば他のサーバ装置1とセッションを確立しているクライアント装置2へ送信されていたはずのメッセージとしてデータベース3に保存する(ステップS305)。送信バッファに残存していたpublish メッセージは消去される。制御部10は、メッセージをデータベース3に保存したことからpubackメッセージを元のpublish メッセージの送信元(パブリッシャ側)へ送信する(ステップS306)。このときデータベース3(「store 」テーブル)には、publish メッセージに含まれるペイロードが識別子と共に保存メッセージとして記憶される。そしてこの保存メッセージの配信先情報として、切断されている他のサーバ装置1を経由したサブスクライバへ送信すべきことを示す情報がデータベース3(「store_target_broker_user」テーブル)に記憶される。このブローカ経由の配信先情報には、情報の識別子(ID)、切断を検知したサーバ装置1の識別情報(broker_id )、切断されている他のサーバ装置1向けに送信した際に使用したパケットID(broker_pid)、送信先のクライアント装置2の識別情報(user_id )及び送信するはずだった保存メッセージの識別子(store_id)を含む。またブローカ経由の配信先情報には、後述のQoS =2の処理で用いられる再送時のパケットID(pid 、再送しているか否か)、及び再送先への送信が完了したか(already_sent他のサーバ装置1からpubrecメッセージを受信しているか)の情報が含まれる。なおテーブル名は例示であることは勿論である。   The control unit 10 treats the extracted status information of the client device 2 as the client device 2 connected to itself, and temporarily stores it (step S303). However, for this client device 2, the message delivery destination is set in the database 3 (see FIG. 8 as in the disconnected state after keep connection). Then, the control unit 10 determines whether or not a publish message for another server device 1 (subscriber side) remains in the transmission buffer according to the processing procedure shown in the flowchart of FIG. 15A (step S304). When it is determined that it remains (S304: YES), the control unit 10 does not use this publish message as halfway message information, but originally a client device 2 that has established a session with another server device 1. Is stored in the database 3 as a message that should have been sent to (step S305). The publish message remaining in the send buffer is deleted. Since the message is stored in the database 3, the control unit 10 transmits the puback message to the transmission source (publisher side) of the original publish message (step S306). At this time, the payload included in the publish message is stored in the database 3 (“store” table) together with the identifier as a saved message. Information indicating that the message should be transmitted to the subscriber via the disconnected other server device 1 is stored in the database 3 (“store_target_broker_user” table) as distribution destination information of the stored message. The distribution destination information via the broker includes an information identifier (ID), identification information (broker_id) of the server device 1 that has detected the disconnection, and a packet ID used when transmitted to the other server device 1 that has been disconnected. (Broker_pid), identification information (user_id) of the destination client apparatus 2, and an identifier (store_id) of the stored message that should have been transmitted. Also, in the distribution destination information via the broker, the packet ID at the time of retransmission (pid, whether it is retransmitted) used in the processing of QoS = 2 described later, and whether transmission to the retransmission destination is completed (already_sent, etc. Information on whether or not a pubrec message is received from the server apparatus 1 is included. Of course, the table name is an example.

ステップS304で残存していないと判断された場合(S304:NO)、publish メッセージに対するpubackメッセージを受信済み、そして元のpublish メッセージの送信元(パブリッシャ側)へpubackを送信済みであるので、そのまま処理を次のステップS307へ進める。   If it is determined in step S304 that the message does not remain (S304: NO), the puback message for the publish message has been received, and the puback has been transmitted to the transmission source (publisher side) of the original publish message. Advances to the next Step S307.

サーバ装置1の制御部10は、該他のサーバ装置1とのセッションを再び確立すると(ステップS307)、「(1.3.)ブローカ間の通信接続」で述べたようにブローカ間の同期処理を実行する(ステップS308)。なお、切断が検知されてから再度セッションが確立するまでの期間は大抵10秒以内、例えば3から5秒である。なお制御部10は、再確立されたブローカ間のセッションはすべて新規のものとして確立され、切断前のセッションにおいて採番していたパケットID等は全てリフレッシュされる。   When the control unit 10 of the server apparatus 1 reestablishes a session with the other server apparatus 1 (step S307), as described in “(1.3.) Communication connection between brokers”, the synchronization process between brokers Is executed (step S308). It should be noted that the period from when disconnection is detected until the session is established again is usually within 10 seconds, for example, 3 to 5 seconds. Note that the control unit 10 establishes all the sessions between the re-established brokers as new ones, and refreshes all the packet IDs and the like assigned in the session before disconnection.

サーバ装置1の制御部10は、自身に接続しているとして一時記憶しているサブスクライバであるクライアント装置2の識別情報と、データベース3に記憶されている各クライアント装置2の接続先の情報(「connections 」)とを照合する(ステップS309)。なお接続先の情報(「connections 」)はサーバ装置1がクライアント装置2とセッションを確立する毎に記憶する情報であって、クライアント装置2(サブスクライバ及びパブリッシャ両方)がいずれのサーバ装置1に通信接続しているかを記憶した情報である。keep接続しているクライアント装置2についての接続先の情報は切断されても、非keep接続がされるまでデータベース3に保持される。なお通信接続先が変更となった場合は、接続先のサーバ装置1の識別情報で上書きされる。   The control unit 10 of the server apparatus 1 identifies the identification information of the client apparatus 2 that is a subscriber temporarily stored as being connected to the server apparatus 1 and the connection destination information of each client apparatus 2 stored in the database 3 (“ "connections") (step S309). The connection destination information (“connections”) is information that is stored each time the server device 1 establishes a session with the client device 2, and the client device 2 (both subscriber and publisher) is connected to any server device 1 for communication. It is the information which memorized whether it is doing. Even if the connection destination information about the client device 2 that is kept connected is disconnected, it is retained in the database 3 until a non-keep connection is made. When the communication connection destination is changed, it is overwritten with the identification information of the connection destination server device 1.

サーバ装置1の制御部10は、ステップS308の照合の結果、自身に通信接続しており状態情報がonlineであるクライアント装置2(複数存在する場合は夫々)について、データベース3に記憶されている接続先の情報に基づき、接続先が自身であるか否かを判断する(ステップS310)。   As a result of the collation in step S308, the control unit 10 of the server device 1 is connected to itself, and the connection stored in the database 3 for the client device 2 (if there are a plurality of devices) whose status information is online. Based on the previous information, it is determined whether or not the connection destination is itself (step S310).

自身でないと判断された場合(S310:NO)、制御部10は、自身に接続しているクライアント装置2の情報の内、対象のサブスクライバであるクライアント装置2の情報を削除し(ステップS311)、再開時の処理を終了する。   When it is determined that it is not itself (S310: NO), the control unit 10 deletes the information of the client device 2 that is the target subscriber from the information of the client device 2 connected to itself (step S311), Terminates the restart process.

ステップS310で自身であると判断された場合(S310:YES)、制御部10はステップS304で残存していると判断されていたか否かを判断する(ステップS312)。残存していると判断されていた場合(S312:YES)、制御部10はステップS305にて送信されていたはずの保存メッセージを読み出し(ステップS313)、サブスクライバであるクライアント装置2へ送信する(ステップS314)。制御部10は、その後送信先のクライアント装置2からpubackメッセージを受信し(ステップS315)、配信先情報及び保存メッセージを削除する(ステップS316)。ステップS312で残存していると判断されていなかった場合(S312:NO)、制御部10はそのまま、セッションの再確立時のメッセージの処理を終了する。   If it is determined in step S310 that it is itself (S310: YES), the control unit 10 determines whether it is determined in step S304 that it remains (step S312). If it is determined that it remains (S312: YES), the control unit 10 reads out the stored message that should have been transmitted in step S305 (step S313), and transmits it to the client device 2 that is a subscriber (step S313). S314). Thereafter, the control unit 10 receives a puback message from the destination client device 2 (step S315), and deletes the distribution destination information and the stored message (step S316). If it is not determined in step S312 that it remains (S312: NO), the control unit 10 ends the message processing at the time of re-establishing the session.

サブスクライブ側のサーバ装置1では、ステップS302、S303は省略して実行される。   In the server device 1 on the subscribing side, steps S302 and S303 are omitted.

図24のフローチャートに示した処理について、具体的に説明する。図25から図27は、図23に示した接続構成におけるブローカ間のセッションGが切断された場合の処理の例を示す説明図である。図25には、セッションGが切断された場合にデータベース3に記憶される情報の内容例を示している。サーバ装置1(b1)は、タイミング(10)におけるパブリッシャからのメッセージに基づき(20)のタイミングで、サーバ装置1(b2)へ向けてpublish メッセージを送信する。サーバ装置1(b1)は、送信先のサーバ装置1(b2)とのセッションの切断を検知する(S301)。サーバ装置1(b1)は、切断されたセッションの接続先のサーバ装置1(b2)にサブスクライバとして通信接続されているはずのクライアント装置2(s1)の識別情報をデータベース3(「keep_sub」テーブル)から抽出する(S302)。サーバ装置1(b1)は、クライアント装置2の識別情報「s1」の状態情報を、配信先をデータベース3に指定して一時記憶する(S303)。(20)のタイミングで送信したpublish メッセージは、pubackメッセージを受信できていないために送信バッファに残存しており(S304:YES)、サーバ装置1(b1)は残存しているpublish メッセージを読み出し、サーバ装置1(b2)から送信されていたはずのメッセージ(保存メッセージ及びブローカ経由の配信先情報)としてデータベース3(「store 」テーブル及び「store_target_broker_user」テーブル)に記憶する(S305)。図25の例では、識別子「345 」の保存メッセージと、この保存メッセージの識別子「345 」を含むブローカ経由の配信先情報(broker_id=b1, broker_pid=0x123, user_id=s1, pid=NULL, store_id=345, already_sent=false)が記憶されている。そしてサーバ装置(b1)は、publish メッセージをデータベース3に保存したので、(30)のタイミングでパブリッシャであるクライアント装置(p1)へpubackメッセージを送信している。これによりサーバ装置1(b1)では、全てのサーバ装置1経由でメッセージを送信できたことを保証した上でパブリッシャであるクライアント装置2へpubackメッセージを返すことができる。   The processing shown in the flowchart of FIG. 24 will be specifically described. 25 to 27 are explanatory diagrams illustrating an example of processing when the session G between brokers in the connection configuration illustrated in FIG. 23 is disconnected. FIG. 25 shows an example of contents of information stored in the database 3 when the session G is disconnected. The server apparatus 1 (b1) transmits a publish message to the server apparatus 1 (b2) at the timing (20) based on the message from the publisher at the timing (10). The server device 1 (b1) detects disconnection of the session with the destination server device 1 (b2) (S301). The server device 1 (b1) stores the identification information of the client device 2 (s1) that should be connected as a subscriber to the server device 1 (b2) to which the disconnected session is connected as a database 3 ("keep_sub" table). (S302). The server device 1 (b1) temporarily stores the status information of the identification information “s1” of the client device 2 by specifying the distribution destination in the database 3 (S303). The publish message transmitted at the timing of (20) remains in the transmission buffer because the puback message cannot be received (S304: YES), and the server apparatus 1 (b1) reads the remaining publish message, It is stored in the database 3 ("store" table and "store_target_broker_user" table) as a message (stored message and delivery destination information via the broker) that should have been transmitted from the server apparatus 1 (b2) (S305). In the example of FIG. 25, the stored message with the identifier “345” and the distribution destination information including the identifier “345” of the stored message (broker_id = b1, broker_pid = 0x123, user_id = s1, pid = NULL, store_id = 345, already_sent = false) is stored. Since the server device (b1) stores the publish message in the database 3, the server device (b1) transmits a puback message to the client device (p1) which is the publisher at the timing of (30). As a result, the server apparatus 1 (b1) can return a puback message to the client apparatus 2 as a publisher after ensuring that the message can be transmitted via all the server apparatuses 1.

なおこのとき、クライアント装置2(s1)が接続しているブローカであるサーバ装置1(b2)で、サーバ装置1(b1)からのpublish メッセージをセッションGの切断前に受信していれば、その後程なく、サーバ装置1(b2)はクライアント装置2(s1)へpublish メッセージを送信し、pubackメッセージを受信するなど処理を実行する。publish メッセージに対してpubackメッセージを送信できていないことについてはセッションの切断によってリフレッシュされるなどすればよい。   At this time, if the server apparatus 1 (b2), which is the broker to which the client apparatus 2 (s1) is connected, receives a publish message from the server apparatus 1 (b1) before disconnecting the session G, then Soon, the server device 1 (b2) performs processing such as transmitting a publish message to the client device 2 (s1) and receiving a puback message. If the puback message cannot be sent in response to the publish message, it can be refreshed by disconnecting the session.

図26は、図25に示した状態から、セッションGが再確立された場合の例を示す。なお、図26の例では、サーバ装置1(b2)がセッションGの切断前にpublish メッセージを受信できていない場合、又はそのタイミングでセッションFについても切断しており、パブリッシャからのpublish メッセージが到達していない場合について説明する。サーバ装置1(b1, b2)間で同期処理が終了すると(S308)、サーバ装置1(b1)は、状態情報を記憶しているクライアント装置2(s1)の識別情報「s1」と、データベース3に記憶されている各クライアント装置2の接続先の情報(「connections 」)における識別情報「s1」とを照合する(S309)。サーバ装置1(b1)は、クライアント装置2(s1)について、接続先情報では自身が接続先ではないので(S310:NO)、クライアント装置2(s1)についての状態情報を削除する(S311)。   FIG. 26 shows an example when the session G is re-established from the state shown in FIG. In the example of FIG. 26, when the server apparatus 1 (b2) has not received the publish message before the session G is disconnected, or the session F is disconnected at that timing, the publish message from the publisher arrives. A case where it has not been described will be described. When the synchronization processing is completed between the server apparatuses 1 (b1, b2) (S308), the server apparatus 1 (b1) receives the identification information “s1” of the client apparatus 2 (s1) storing the state information and the database 3 Is compared with the identification information “s1” in the connection destination information (“connections”) of each client device 2 stored in (S309). Since the server apparatus 1 (b1) is not the connection destination in the connection destination information for the client apparatus 2 (s1) (S310: NO), the server apparatus 1 (b1) deletes the status information about the client apparatus 2 (s1) (S311).

サーバ装置1(b2)側でも、サーバ装置1(b1)とのセッションを再確立すると(S307)、同期処理を行なう(S308)。サーバ装置1(b2)は、状態情報を記憶しているクライアント装置2(s1)の識別情報「s1」と、データベース3に記憶されている各クライアント装置2の接続先情報(「connections 」)における識別情報「s1」とを照合する(S309)。サーバ装置1(b2)は、クライアント装置2(s1)について自身が接続先であると判断する(S310:YES)。サーバ装置1(b2)は、データベース3(「store 」及び「store_target_broker_user」テーブル)に記憶されている保存メッセージ及びブローカ経由の配信先情報に基づきpublish メッセージを読み出し(S313)パケットIDを採番して例えば(50)のタイミングでクライアント装置2(s1)へ送信する(S314)。その後(60)のタイミングでクライアント装置2(s1)から返されるpubackメッセージをサーバ装置(b2)が受信することで(S315)、保存メッセージ及び配信先情報は削除される(S316)。これにより、ブローカ・ブローカ間が切断されたとしてもサブスクライバ側へのQoS =1(「At least One」)でのメッセージの到達を達成できる。仮に、セッションGが切断されたときにサーバ装置1(b2)側でpublish メッセージを受信できていて、これをサブスクライバであるクライアント装置2(s1)に送信済みであった場合、ブローカ・ブローカ間の切断によって保存された保存メッセージ及び配信先情報に基づいて別途新たなパケットIDで同一の内容のpublish メッセージが送信されることになる。しかしながら、QoS =1は最低1回受信であるから問題はない。   Also on the server device 1 (b2) side, when a session with the server device 1 (b1) is re-established (S307), synchronization processing is performed (S308). The server apparatus 1 (b2) uses the identification information “s1” of the client apparatus 2 (s1) storing the state information and the connection destination information (“connections”) of each client apparatus 2 stored in the database 3. The identification information “s1” is collated (S309). The server apparatus 1 (b2) determines that the client apparatus 2 (s1) is a connection destination (S310: YES). The server device 1 (b2) reads the publish message based on the stored message stored in the database 3 ("store" and "store_target_broker_user" table) and the delivery destination information via the broker (S313), and assigns the packet ID. For example, it transmits to the client apparatus 2 (s1) at the timing of (50) (S314). Thereafter, when the server device (b2) receives the puback message returned from the client device 2 (s1) at the timing of (60) (S315), the stored message and the delivery destination information are deleted (S316). As a result, even when the broker / broker is disconnected, it is possible to achieve message arrival at the subscriber side with QoS = 1 (“At least One”). If the publish message has been received on the server device 1 (b2) side when the session G is disconnected and has been transmitted to the client device 2 (s1) as a subscriber, the broker / broker A publish message having the same content is transmitted separately with a new packet ID based on the stored message stored by the disconnection and the delivery destination information. However, since QoS = 1 is received at least once, there is no problem.

図27は、ブローカ間のセッションGが再確立された後の処理の他の例を示す説明図である。図27は、図25に示した状態から、セッションGが再確立されるがその前に、サーバ装置1(b2)とセッションを確立させていたサブスクライバであるクライアント装置2(s1)が、セッションGの切断中にサーバ装置1(b1)へ接続先を変更する事態が発生した場合の例を示す。図27において、クライアント装置2(s1)がサーバ装置1(b1)へセッション確立をリクエストし、これが承諾されるとサーバ装置1(b1)がデータベース3における接続先情報を識別情報「b1」に書き換える。この後同期処理が実行され、サーバ装置1(b1及びb2)間で接続情報が共有される。この場合、サーバ装置1(b1)は、状態情報を記憶しているクライアント装置2の識別情報「s1」と、データベース3に記憶されている各クライアント装置2の接続先情報(「connections 」)における識別情報「s1」とを照合し(S309)、接続先情報でも自身が接続先であると判断する(S310:YES)。サーバ装置1(b1)は、例えば(50)のタイミングでデータベース3(「store 」及び「store_target_broker_user」テーブル)に記憶されているサーバ装置1(b2)から送信されるはずであったpublish メッセージを読み出し(S313)、新たなパケットIDでクライアント装置2(s1)へpublish メッセージを送信する(S314)。データベース3に記憶されていた保存メッセージ及び配信先情報は、(60)のタイミングでクライアント装置2(s1)から送信されたpubackメッセージをサーバ装置1(b1)が受信することで(S315)、削除される(S316)。   FIG. 27 is an explanatory diagram showing another example of processing after the session G between brokers is re-established. In FIG. 27, the session G is re-established from the state shown in FIG. 25, but before that, the client device 2 (s1), which is a subscriber who has established a session with the server device 1 (b2), An example in the case where a situation occurs in which the connection destination is changed to the server device 1 (b1) during disconnection is shown. In FIG. 27, the client device 2 (s1) requests the server device 1 (b1) to establish a session, and if this is accepted, the server device 1 (b1) rewrites the connection destination information in the database 3 to the identification information “b1”. . Thereafter, synchronization processing is executed, and connection information is shared between the server apparatuses 1 (b1 and b2). In this case, the server apparatus 1 (b1) uses the identification information “s1” of the client apparatus 2 storing the state information and the connection destination information (“connections”) of each client apparatus 2 stored in the database 3. The identification information “s1” is collated (S309), and it is determined that the connection destination information itself is the connection destination (S310: YES). The server device 1 (b1) reads the publish message that should have been transmitted from the server device 1 (b2) stored in the database 3 (“store” and “store_target_broker_user” table) at the timing of (50), for example. (S313) A publish message is transmitted to the client apparatus 2 (s1) with a new packet ID (S314). The stored message and the delivery destination information stored in the database 3 are deleted when the server device 1 (b1) receives the puback message transmitted from the client device 2 (s1) at the timing (60) (S315). (S316).

図27で示す例においてサーバ装置1(b2)側では、サーバ装置1(b1)とのセッションを再確立すると(S307)、同期処理を行なう(S308)。サーバ装置1(b2)は、状態情報とデータベース3に記憶されている各クライアント装置2の接続先情報(「connections 」)における識別情報「s1」を照合し(S309)、自身が接続先でないと判断する(S310:NO)。サーバ装置1(b2)は、クライアント装置2(s1)についての状態情報を削除する(S311)。クライアント装置2(s1)向けの処理は上述のようにサーバ装置1(b1)側に任される。   In the example shown in FIG. 27, when the server device 1 (b2) side re-establishes a session with the server device 1 (b1) (S307), synchronization processing is performed (S308). The server device 1 (b2) collates the identification information “s1” in the connection destination information (“connections”) of each client device 2 stored in the database 3 with the status information (S309), and if it is not the connection destination itself Judgment is made (S310: NO). The server apparatus 1 (b2) deletes the status information about the client apparatus 2 (s1) (S311). The processing for the client device 2 (s1) is left to the server device 1 (b1) side as described above.

このように、MQTTモデルにおける到達保証のメッセージのやり取りの途中でブローカ間のセッションが切断された場合であっても、パブリッシャであるクライアント装置2からサブスクライバであるクライアント装置2までの経路におけるメッセージの到達保証をQoS =1とすることができる。   As described above, even when the session between brokers is disconnected during the exchange of the message for guaranteeing arrival in the MQTT model, the message arrives in the path from the client device 2 as a publisher to the client device 2 as a subscriber. The guarantee can be QoS = 1.

次に図24のフローチャートにおけるステップS305及びステップS306の間、セッションを再確立する間に新たにパブリッシャ又はパブリッシャ側の他のサーバ装置1からpublish メッセージを受信した場合の処理について説明する。図28は、ブローカ間切断中のメッセージ処理手順の一例を示すフローチャートである。なお図28のフローチャートに示す処理手順の内、図20のフローチャートと共通する手順については同一のステップ番号を付して詳細な説明を省略する。   Next, a process when a publish message is newly received from the publisher or another server device 1 on the publisher side during the session re-establishment during steps S305 and S306 in the flowchart of FIG. 24 will be described. FIG. 28 is a flowchart illustrating an example of a message processing procedure during disconnection between brokers. Of the processing procedures shown in the flowchart of FIG. 28, the same steps as those in the flowchart of FIG.

ブローカであるサーバ装置1の制御部10は、publish メッセージを受信して(S201)、このメッセージを他のサーバ装置1へ送信すると判断した場合(S203:YES)、送信先のサーバ装置1のいずれかとの間のセッションが切断しているか否かを判断する(ステップS211)。セッションが切断していないと判断された場合(S211)、制御部10は他のサーバ装置1へpublish メッセージを送信し(S206)、他のサーバ装置1全てからpubackメッセージを受信したと判断してから(S207:YES)、送信元へpubackメッセージを返す(S208)。   When the control unit 10 of the server device 1 that is the broker receives the publish message (S201) and determines that this message is to be transmitted to another server device 1 (S203: YES), any of the server devices 1 that are the transmission destinations. It is determined whether or not the session between the two is disconnected (step S211). When it is determined that the session is not disconnected (S211), the control unit 10 transmits a publish message to the other server apparatus 1 (S206), and determines that the puback message has been received from all the other server apparatuses 1. From (S207: YES), a puback message is returned to the transmission source (S208).

ステップS211にてセッションが切断していると判断した場合(S211:YES)、制御部10は相手のサーバ装置1を通信接続先とするサブスクライバであるクライアント装置2についてのセッション情報をデータベース3(「keep_sub」テーブル)から参照する(ステップS212)。制御部10は参照したセッション情報に基づき、抽出して記憶しているサブスクライバの状態情報を更新する(ステップS213)。例えば、図24のフローチャートにおけるステップS303で記憶していたサブスクライバが、切断中にサブスクライブを停止していた場合には、これを反映し、以後のpublish メッセージの配信先から除外してもよくなる。制御部10は、更新した状態情報に基づき、配信先をデータベース3としているサブスクライバであるクライアント装置2に関し、ステップS201で受信したpublish メッセージについてデータベース3(「store 」及び「store_target」テーブル)に保存メッセージ及び配信先情報を記憶する(ステップ214)。そして制御部10は、切断中のメッセージの処理を終了する。   When it is determined in step S211 that the session is disconnected (S211: YES), the control unit 10 stores the session information about the client device 2 that is a subscriber whose communication connection destination is the partner server device 1 in the database 3 (“ Reference is made from the “keep_sub” table) (step S212). Based on the referenced session information, the control unit 10 updates the subscriber status information extracted and stored (step S213). For example, if the subscriber stored in step S303 in the flowchart of FIG. 24 has stopped subscribing during disconnection, this may be reflected and excluded from the distribution destination of subsequent publish messages. Based on the updated status information, the control unit 10 relates to the client device 2 that is a subscriber whose distribution destination is the database 3, and stores the publish message received in step S201 in the database 3 ("store" and "store_target" tables). The distribution destination information is stored (step 214). Then, the control unit 10 ends the processing of the message being disconnected.

切断から復帰した場合には、図24のフローチャートのステップS310以降で、サブスクライバの接続先に応じて、いずれかのサーバ装置1が、データベース3からpublish メッセージを配信すればよい。   When returning from the disconnection, any server device 1 may distribute the publish message from the database 3 in accordance with the connection destination of the subscriber in step S310 and subsequent steps in the flowchart of FIG.

図28のフローチャートに示したように、サーバ装置1の制御部10は、切断中(大抵の場合3秒から5秒の間)、publish メッセージを受信する都度、その間における各クライアント装置2の接続先の情報を自身が一時的に記憶している状態情報を適応させる。切断されたセッションの相手であるサーバ装置1を通信接続先とするサブスクライバのクライアント装置2がその切断中に、トピックのサブスクライブを止めたり(unsubscribe )、新たにサブスクライブしたり、他のトピックをサブスクライブしたりした場合にも、状態情報を適応させて間違いなくメッセージを送信することが可能になる。   As shown in the flowchart of FIG. 28, the control unit 10 of the server device 1 is disconnected (in most cases, between 3 seconds and 5 seconds), and each time a publish message is received, the connection destination of each client device 2 during that time The state information in which the information itself is temporarily stored is adapted. During the disconnection, the subscriber client device 2 whose communication destination is the server device 1 that is the partner of the disconnected session stops subscribing (unsubscribe), newly subscribes, and other topics Even in the case of subscribing, the message can be transmitted without fail by adapting the state information.

ブローカのダウンを保証外とする場合、データベース3への情報の記憶は最低限としてあるから、QoS =1を保証しつつも送受信の速度が低減することが回避される。その代わり、ブローカであるサーバ装置1はいずれもダウンした場合には、自身に接続しているクライアント装置2の状態情報(online又はdatabase等)の一時記憶を全て失う。ブローカ間のセッションは起動時に新規に確立されるので、セッションに対応して記憶されている情報もダウン時に全て失われることになる。ステップS309等の照合ができないから、QoS =1のメッセージは失われることになる。   When broker down is not guaranteed, information is stored in the database 3 at a minimum, so that it is possible to avoid a reduction in transmission / reception speed while guaranteeing QoS = 1. Instead, when all of the server devices 1 that are brokers are down, all temporary storage of status information (such as online or database) of the client device 2 connected to itself is lost. Since a session between brokers is newly established at the time of startup, all information stored corresponding to the session is lost when the session is down. Since collation in step S309 and the like cannot be performed, the message with QoS = 1 is lost.

(3)QoS =1、ブローカダウン保証
ブローカがダウンした場合もメッセージの到達を保証するという前提において、(2)同様に、経路である全てのセッションにてQoS が「1」に調停されるQoS =1が指定されたpublish メッセージのサブスクライバまでの到達について説明する。つまり(2)同様に、サブスクライバであるクライアント装置2が当該トピックを、QoS =1又は=2で指定している状態で、当該トピックについてパブリッシャがQoS =1を指定してpublish メッセージを送信するケースである。このメッセージについてトピック指定時に「0」を指定しているサブスクライバへの送信する場合の処理は(1)で述べたので説明を省略する。
(3) QoS = 1, broker down guarantee Assuming that message arrival is guaranteed even when the broker goes down, QoS is adjusted so that QoS is “1” in all sessions on the path as in (2). Explain how the publish message with = 1 specified reaches the subscriber. That is, (2) Similarly, when the client device 2 which is a subscriber specifies the topic with QoS = 1 or = 2, the publisher sends a publish message specifying QoS = 1 for the topic. It is. The processing for transmitting this message to a subscriber who designates “0” at the time of specifying a topic has been described in (1), and will not be described.

(3.1)正常運用時
ブローカがダウンした場合にメッセージの到達を保証する場合、ダウンしたことを自身で検知できないので、ダウンした場合の処理に切り替えるといったことができない。したがってダウン時に到達を保証するか否かは、ブローカ(サーバ装置1)のインスタンスが生成された時点で選択される。そしてダウンした場合にも到達保証を行なうことを選択して起動したブローカであるサーバ装置1は基本的に、自身にkeep接続しているクライアント装置2が1つでも存在する限り、パブリッシャであるクライアント装置又は他のサーバ装置1からpublish メッセージを受信する都度、データベース3(「store」及び「store_target」テーブル)に保存メッセージ及び配信先情報を保存する。そしてサーバ装置1は、publish メッセージに対するpubackメッセージを受信する都度、それらの保存メッセージ及び配信先情報を更新又は削除する処理を実行する(図7から図12参照)。サーバ装置1は、自身にサブスクライバであるクライアント装置2が通信接続している場合には、publish メッセージを送信してからパブリッシャであるクライアント装置2側へpubackメッセージを送信する順序性を守る。同様にしてサーバ装置1は、他のサーバ装置1へ向けてpublish メッセージを送信する場合には、他のサーバ装置1全てからpubackメッセージを受信してからパブリッシャであるクライアント装置2側へpubackメッセージを送信する順序性を守る(図20から図22参照)。
(3.1) During normal operation When message arrival is guaranteed when the broker is down, it cannot be detected by itself, so it cannot be switched to processing when it is down. Therefore, whether to guarantee arrival when down is selected when an instance of the broker (server apparatus 1) is generated. The server device 1 that is a broker activated by selecting to perform arrival guarantee even when it goes down is basically a client that is a publisher as long as there is at least one client device 2 that is kept connected to itself. Each time a publish message is received from a device or another server device 1, the storage message and the delivery destination information are stored in the database 3 (“store” and “store_target” tables). Each time the server apparatus 1 receives a puback message for a publish message, the server apparatus 1 executes a process of updating or deleting the stored message and the delivery destination information (see FIGS. 7 to 12). When the client apparatus 2 as a subscriber is connected to the server apparatus 1 by communication, the server apparatus 1 keeps the order of transmitting the puback message to the client apparatus 2 as a publisher after transmitting the publish message. Similarly, when the server apparatus 1 transmits a publish message to another server apparatus 1, the server apparatus 1 receives the puback message from all the other server apparatuses 1 and then sends the puback message to the client apparatus 2 side that is the publisher. The order of transmission is maintained (see FIGS. 20 to 22).

図29は、ブローカダウンを保証するサーバ装置1における送信手順の一例を示すフローチャートである。なお図29のフローチャートに示す処理手順は、図4のフローチャートに示した手順の内のステップS9の詳細に対応する。また図29のフローチャートに示す処理手順の内、ブローカダウンを保証外とする際の図20のフローチャートに示した処理手順と共通する手順については同一のステップ番号を付して詳細な説明を省略する。   FIG. 29 is a flowchart illustrating an example of a transmission procedure in the server apparatus 1 that guarantees broker down. The processing procedure shown in the flowchart of FIG. 29 corresponds to the details of step S9 in the procedure shown in the flowchart of FIG. Also, among the processing procedures shown in the flowchart of FIG. 29, the steps common to the processing procedure shown in the flowchart of FIG. 20 when broker down is not guaranteed are assigned the same step numbers and detailed description is omitted. .

サーバ装置1の制御部10は、ステップS201でpublish メッセージを受信した場合(S201:YES)、且つ、送信先に他のサーバ装置1が含まれないと判断された場合(SS203:NO)、ステップS202で抽出したトピックについての送信先に、keep接続を選択して通信接続しているサブスクライバであるクライアント装置2が存在するか否かを判断する(ステップS221)。keep接続を選択しているクライアント装置2が存在しないと判断された場合(S221:NO)、サーバ装置1の制御部10は、自身に通信接続しているクライアント装置2へpublish メッセージを送信し(S204)、送信元へpubackメッセージを返す(S205)。ステップS221にて、keep接続を選択しているクライアント装置2が存在すると判断された場合(S221:YES)、セッションの切断が発生しているか否かに拘わらず、制御部10は、publish メッセージ及びkeep接続である配信先の情報を保存メッセージ及び配信先情報としてデータベース3(「store 」及び「store_target」テーブル)に記憶してから(ステップS222)、対象となるクライアント装置2へpublish メッセージを送信する(S204)。   When the publish message is received in step S201 (S201: YES), and the control unit 10 of the server device 1 determines that no other server device 1 is included in the transmission destination (SS203: NO), It is determined whether or not there is a client apparatus 2 that is a subscriber connected by communication by selecting keep connection as the transmission destination for the topic extracted in S202 (step S221). When it is determined that there is no client device 2 that has selected keep connection (S221: NO), the control unit 10 of the server device 1 transmits a publish message to the client device 2 that is connected to and communicates with itself (S221: NO). In step S204, a puback message is returned to the transmission source (S205). If it is determined in step S221 that there is a client device 2 that has selected keep connection (S221: YES), the control unit 10 determines whether the publish message and the session message are disconnected regardless of whether or not a session disconnection has occurred. The information of the delivery destination that is the keep connection is stored in the database 3 (“store” and “store_target” tables) as a stored message and delivery destination information (step S222), and then a publish message is transmitted to the target client device 2. (S204).

そしてサーバ装置1の制御部10は、pubackメッセージをpublish メッセージの送信元側へ送信した後(S205)、制御部10は再度、ステップS221にて存在すると判断したか否かを判断する(ステップS223)。存在すると判断していないと判断された場合(S223:NO)、制御部10は、そのまま1回のpublish メッセージの受信処理を終了する。   Then, the control unit 10 of the server device 1 transmits the puback message to the publish message transmission source side (S205), and then determines whether or not the control unit 10 determines again that it exists in step S221 (step S223). ). If it is determined that it does not exist (S223: NO), the control unit 10 ends the process of receiving one publish message as it is.

ステップS223にて存在すると判断されていた場合(S223:YES)、制御部10は、その存在するクライアント装置2、即ち抽出されたトピックを指定して自身にkeep接続しているクライアント装置2からpubackメッセージを受信したか否かを判断する(ステップS224)。受信していないと判断された場合(S224:NO)、制御部10は受信したと判断するまでは、次のステップS225の処理は行なわない。pubackメッセージを受信したと判断された場合(S224:YES)、制御部10は、ステップS222で記憶したpublish メッセージ及びkeep接続の送信先の情報をデータベース3から削除し(ステップS225)、publish メッセージの受信処理を終了する。   If it is determined in step S223 that it exists (S223: YES), the control unit 10 pubacks from the existing client device 2, that is, the client device 2 that keeps connected to itself by specifying the extracted topic. It is determined whether a message has been received (step S224). If it is determined that it has not been received (S224: NO), the process of the next step S225 is not performed until the control unit 10 determines that it has been received. When it is determined that the puback message has been received (S224: YES), the control unit 10 deletes the publish message and keep connection destination information stored in step S222 from the database 3 (step S225), and The reception process ends.

ステップS203にて他のサーバ装置1が含まれると判断された場合(S203:YES)、制御部10は、データベース3で共有しているセッション情報(「keep_sub」)から、ステップS202で抽出したトピックについて送信先の他のサーバ装置1からの送信先にkeep接続を選択して通信接続しているサブスクライバが存在するか否かを判断する(ステップS226)。ステップS226にて存在しないと判断された場合(S226:NO)、制御部10はそのままpublish メッセージを他のサーバ装置1へ送信する(S206)。この場合制御部10は、当該トピックをサブスクライブしている他のサーバ装置1全てからpubackメッセージを受信してから(S207:YES)、送信元へ向けてpubackメッセージを送信し(S208)、publish メッセージの受信処理を終了する。   When it is determined in step S203 that another server device 1 is included (S203: YES), the control unit 10 extracts the topic extracted in step S202 from the session information ("keep_sub") shared in the database 3 It is determined whether or not there is a subscriber connected for communication by selecting keep connection as the transmission destination from the other server apparatus 1 of the transmission destination (step S226). If it is determined in step S226 that it does not exist (S226: NO), the control unit 10 transmits the publish message as it is to another server device 1 (S206). In this case, the control unit 10 receives the puback message from all the other server apparatuses 1 that subscribe to the topic (S207: YES), and then transmits the puback message to the transmission source (S208). The message reception process ends.

ステップS226にて存在すると判断された場合(S226:YES)、セッションの切断が発生しているか否かに拘わらず、制御部10は、publish メッセージ(保存メッセージ)及びkeep接続の配信先情報をデータベース3(「store 」及び「store_target_broker 」テーブル)に記憶してから(ステップS227)、他のサーバ装置1へpublish メッセージを送信する(S206)。   If it is determined in step S226 that the session exists (S226: YES), the control unit 10 stores the publish message (stored message) and keep connection distribution destination information in the database regardless of whether or not the session is disconnected. 3 ("store" and "store_target_broker" table) (step S227), and then transmits a publish message to the other server apparatus 1 (S206).

サーバ装置1の制御部10は、当該トピックをサブスクライブしている他のサーバ装置1全てからpubackメッセージを受信してから(S207:YES)、送信元へ向けてpubackメッセージを送信した後(S208)、制御部10は再度、ステップS226にて、keep接続を選択して通信接続しているサブスクライバであるクライアント装置2が存在すると判断したか否かを判断する(ステップS228)。存在しないと判断された場合(S228:NO)、制御部10は、そのまま1回のpublish メッセージの受信処理を終了する。   The control unit 10 of the server apparatus 1 receives the puback message from all the other server apparatuses 1 that subscribe to the topic (S207: YES), and then transmits the puback message to the transmission source (S208). In step S226, the control unit 10 again determines whether or not it is determined that there is a client device 2 that is a subscriber connected by communication by selecting keep connection (step S228). If it is determined that it does not exist (S228: NO), the control unit 10 ends the process of receiving one publish message as it is.

ステップS228にて存在すると判断された場合(S228:YES)、ステップS227で記憶したpublish メッセージ及びkeep接続の送信先の情報(保存メッセージ及び配信先情報)をデータベース3から削除し(ステップS229)、publish メッセージの受信処理を終了する。   If it is determined in step S228 that it exists (S228: YES), the publish message and keep connection destination information (stored message and delivery destination information) stored in step S227 are deleted from the database 3 (step S229). Terminates publish message reception processing.

図29のフローチャートに示した処理について、図面を参照して具体的に説明する。図30から図33は、QoS =1でブローカダウンを保証する際の処理を示す図である。図30は、パブリッシャであるクライアント装置2(p1)、及び、サブスクライバであるクライアント装置2(s1, s2)と夫々セッションA,B,Cを確立しているサーバ装置1(b1)における処理を示している。サーバ装置1(b1)は、パブリッシャであるクライアント装置2(p1)からトピック「t1」について(10)のタイミングでpublish メッセージを受信すると(S201:YES)、トピック「t1」を指定してkeep接続を選択して通信接続しているクライアント装置2(s1)へ受信したpublish メッセージを(20)のタイミングで送信する(S204)。サーバ装置1(b1)はその前に、データベース3(「store 」及び「store_target」テーブル)に、メッセージの内容「a 」を含む保存メッセージと、識別情報「s1」を配信先とする配信先情報とを、publish メッセージを送信する際に採番したパケットIDと共に記憶する(S222)。サーバ装置1は、トピック「t1」のpublish メッセージについて、クライアント装置2(s2)もトピック「t1」を指定しているので(20)のタイミングで送信するが(S204)、クライアント装置2(s2)はkeep接続を選択していないので、識別情報「s2」の配信先情報はデータベース3に記憶されない。   The processing shown in the flowchart of FIG. 29 will be specifically described with reference to the drawings. FIG. 30 to FIG. 33 are diagrams showing processing when guaranteeing broker down with QoS = 1. FIG. 30 shows processing in the client apparatus 2 (p1) as a publisher and the server apparatus 1 (b1) that has established sessions A, B, and C with the client apparatus 2 (s1, s2) as subscribers. ing. When the server apparatus 1 (b1) receives a publish message for the topic “t1” from the publisher client apparatus 2 (p1) at the timing (10) (S201: YES), the server apparatus 1 (b1) specifies the topic “t1” and keep connection The received publish message is transmitted at the timing of (20) to the client apparatus 2 (s1) connected by communication selection (S204). Before that, the server device 1 (b1) stores the destination message in the database 3 (“store” and “store_target” table) including the stored message including the message content “a” and the identification information “s1”. Are stored together with the packet ID number assigned when the publish message is transmitted (S222). The server apparatus 1 transmits the publish message of the topic “t1” at the timing of (20) because the client apparatus 2 (s2) also specifies the topic “t1” (S204), but the client apparatus 2 (s2) Since the keep connection is not selected, the distribution destination information of the identification information “s2” is not stored in the database 3.

図31は、図30の状態よりも時間が経過した後の処理を示している。まずサーバ装置1は、クライアント装置2(s1, s2)へpublish メッセージを送信したことで次のタイミング(30)でパブリッシャであるクライアント装置2(p1)へpubackメッセージを送信する。これに前後して(例えばタイミング(35)にて)クライアント装置2(s1)からpubackメッセージが送信された場合、サーバ装置1は、パケットID及びpubackメッセージの送信元をキーとしてデータベース3(「store_target」テーブル)から配信先情報を検索する。keep接続を選択していないクライアント装置2(s2)についての検索結果はゼロ(空)であるが、keep接続を選択しているクライアント装置2(s1)については図31に示すように検索される。サーバ装置1(b1)は、このpubackメッセージの受信を機に、レコードを削除する(S225)。サーバ装置1(b1)は、同一の保存メッセージ(「store 」テーブルにおける識別子:123 の情報)について配信先情報が空になったと判断された場合、参照されなくなった保存メッセージとしてこれをデータベース3(「store 」テーブル)から削除する(S225)。   FIG. 31 shows processing after a lapse of time from the state of FIG. First, the server apparatus 1 transmits a puback message to the client apparatus 2 (p1) as the publisher at the next timing (30) by transmitting the publish message to the client apparatus 2 (s1, s2). When a puback message is transmitted from the client device 2 (s1) before or after this (for example, at timing (35)), the server device 1 uses the packet ID and the transmission source of the puback message as a key in the database 3 (“store_target "Destination information is searched from" table "). The search result for the client device 2 (s2) not selecting the keep connection is zero (empty), but the client device 2 (s1) selecting the keep connection is searched as shown in FIG. . The server apparatus 1 (b1) deletes the record upon receiving this puback message (S225). When the server apparatus 1 (b1) determines that the delivery destination information is empty for the same stored message (identifier: 123 information in the “store” table), the server apparatus 1 (b1) uses this as the stored message that is no longer referenced. Delete from the “store” table) (S225).

図32は、トピック「t1」についてのパブリッシャであるクライアント装置2(p1)とセッションEを確立しているブローカであるサーバ装置1(b1)における処理を示している。サーバ装置1(b1)は、トピック「t1」を指定トピックとするサブスクライバであるクライアント装置2(s1)が接続している他のサーバ装置1(b2)とメッセージを仲介する。サーバ装置1(b1)は、パブリッシャであるクライアント装置2(p1)からトピック「t1」について(10)のタイミングでpublish メッセージを受信する(S201:YES)。この場合、サーバ装置1(b1)は、サーバ装置1(b2)に対し、トピック「t1」を指定してkeep接続を選択して通信接続しているクライアント装置2(s1)が存在していると判断する(S226:YES)。サーバ装置1(b1)は、パブリッシャから受信したpublish メッセージを(20)のタイミングで送信するが(S206)、その前に、データベース3(「store 」及び「store_target_broker 」テーブル)へ、保存メッセージ及び配信先情報を記憶する(S227)。図32例では、識別子「567 」の保存メッセージと、この保存メッセージの識別子「567 」と、送信時に使用されたパケットID「0x123 」を含むブローカ間の配信先情報(source_id=b1, target_id=b2, packet_id=0x123, store_id=567, already_sent=false )が記憶されている。   FIG. 32 shows processing in the server apparatus 1 (b1) that is the broker that has established the session E with the client apparatus 2 (p1) that is the publisher for the topic “t1”. The server device 1 (b1) mediates a message with another server device 1 (b2) to which the client device 2 (s1), which is a subscriber having the topic “t1” as a designated topic, is connected. The server apparatus 1 (b1) receives a publish message for the topic “t1” from the client apparatus 2 (p1), which is the publisher, at the timing of (10) (S201: YES). In this case, the server apparatus 1 (b1) has a client apparatus 2 (s1) that is connected to the server apparatus 1 (b2) by specifying the topic “t1” and selecting keep connection. (S226: YES). The server apparatus 1 (b1) transmits the publish message received from the publisher at the timing of (20) (S206), but before that, the stored message and distribution to the database 3 ("store" and "store_target_broker" tables) The previous information is stored (S227). In the example of FIG. 32, the distribution destination information (source_id = b1, target_id = b2) including the storage message with the identifier “567”, the identifier “567” of the storage message, and the packet ID “0x123” used at the time of transmission. , packet_id = 0x123, store_id = 567, already_sent = false) are stored.

図33は、図32の状態よりも時間が経過した後の処理を示している。サーバ装置1(b2)は、サーバ装置1(b1)から送信されたpublish メッセージを、サブスクライバであるクライアント装置2(s1)へ送信したことで次のタイミング(40)にpubackメッセージを送信する。クライアント装置2(s1)から(45)のタイミングでpubackメッセージが送信されたとしてもこれを待つことなくサーバ装置1(b2)からpubackメッセージが送信される。サーバ装置1(b1)は、他のサーバ装置1全て(b2)からのpubackメッセージを受信すると(S207:YES)、パブリッシャであるクライアント装置2(p1)へ、例えば(50)のタイミングでpubackメッセージを送信する(S208)。サーバ装置1(b1)は、サーバ装置1(b2)からpubackメッセージを受信した場合、パケットID及びpubackメッセージの送信元(target_id=b2)をキーとしてデータベース3(「store_target_broker 」テーブル)から配信先情報を検索する。ステップS226にてkeep接続を選択して通信接続しているクライアント装置2(s1)が存在していると判断され(S228:YES)、配信先情報が検索されるはずであるから、サーバ装置1(b1)は、検索結果の配信先情報をデータベース3(「store_target_broker 」テーブル)から削除する(S229)。サーバ装置1(b1)は、同一の保存メッセージ(「store 」テーブルにおける識別子:567 )について配信先情報が空になったと判断された場合、参照されなくなった保存メッセージをデータベース3(「store 」テーブル)から削除する(S229)。   FIG. 33 shows processing after a lapse of time from the state of FIG. The server apparatus 1 (b2) transmits the puback message at the next timing (40) by transmitting the publish message transmitted from the server apparatus 1 (b1) to the client apparatus 2 (s1) as the subscriber. Even if the puback message is transmitted at the timing of (45) from the client device 2 (s1), the puback message is transmitted from the server device 1 (b2) without waiting for this. When the server apparatus 1 (b1) receives the puback message from all the other server apparatuses 1 (b2) (S207: YES), the puback message is sent to the client apparatus 2 (p1) as the publisher, for example, at the timing of (50). Is transmitted (S208). When the server apparatus 1 (b1) receives the puback message from the server apparatus 1 (b2), the distribution destination information from the database 3 ("store_target_broker" table) with the packet ID and the source of the puback message (target_id = b2) as a key Search for. In step S226, it is determined that there is a client device 2 (s1) that is in communication connection by selecting keep connection (S228: YES), and distribution destination information should be searched. (B1) deletes the distribution destination information of the search result from the database 3 (“store_target_broker” table) (S229). When the server apparatus 1 (b1) determines that the delivery destination information is empty for the same stored message (identifier: 567 in the “store” table), the server apparatus 1 (b1) stores the stored message that is no longer referred to in the database 3 (“store” table). ) (S229).

ブローカダウン時もメッセージの到達を保証することを選択して起動したブローカであるサーバ装置1(b1)は起動後、切断又はブローカダウンが発生していない間も図29から図33に示した処理を実行する。publish メッセージを受信する都度、データベース3への書き込みが実行され、pubackメッセージを受信する都度、削除が実行されるため、keep接続しているクライアント装置2が存在する場合にはメッセージの送受信にある程度の時間を要する。この点で、データベース3をKVS(Key-Value Store )で構成し、作成、更新及び削除を全てイベントとして記憶する処理とすることで、データベース3への処理に要する時間を可及的に削減することが可能になる。   The server apparatus 1 (b1), which is a broker activated by selecting to guarantee the arrival of a message even when the broker is down, is processed as shown in FIG. 29 to FIG. 33 even if no disconnection or broker down occurs after the activation. Execute. Every time a publish message is received, writing to the database 3 is executed, and every time a puback message is received, deletion is executed. Therefore, when there is a client device 2 connected to keep, there is a certain amount of message transmission / reception. It takes time. In this regard, the database 3 is configured by KVS (Key-Value Store), and all the creations, updates, and deletions are stored as events, thereby reducing the time required for processing to the database 3 as much as possible. It becomes possible.

(3.2)切断又はダウン発生時
セッションの切断が発生した場合は、サーバ装置1は夫々、その切断を検知することができ、図24のフローチャートに示した処理と同一の処理を実行する。なおQoS =1でブローカダウン時にもメッセージの到達を保証する場合、上述したようにkeep接続しているクライアント装置2について、各サーバ装置1は正常運用時もデータベース3への記憶及び削除を繰り返し実行している。切断の原因が他のサーバ装置1のブローカダウンである場合、ブローカダウン時もメッセージを保証するケースでは、ネットワークコントローラの送信バッファにメッセージが残存しているか否かではなく、データベース3(「store_target_broker 」テーブル)に削除されていない保存メッセージ及び配信先情報が残存しているか否かを判断する。つまりサーバ装置1は、図24のフローチャートにおけるステップS304において、送信バッファではなく、データベース3にメッセージが残存しているか否かを判断する。そして残存していると判断された場合(S304:YES)、制御部10は、データベース3に残存していたメッセージを、本来であれば他のサーバ装置1とセッションを確立しているクライアント装置2へ送信されていたはずのメッセージ(保存メッセージ及びブローカ経由の配信先情報)としてデータベース3(「store_target_broker_user」テーブル)に保存(移動)する(S305)。
(3.2) When disconnection or down occurs When a session disconnection occurs, each of the server devices 1 can detect the disconnection, and executes the same processing as the processing shown in the flowchart of FIG. When guaranteeing message arrival even when the broker is down with QoS = 1, each server device 1 repeatedly stores and deletes data in the database 3 even during normal operation for the client device 2 with keep connection as described above. is doing. When the cause of the disconnection is a broker down of another server apparatus 1, in the case of guaranteeing the message even when the broker is down, it is not the database remaining in the transmission buffer of the network controller, but the database 3 (“store_target_broker” It is determined whether the stored message and the delivery destination information that have not been deleted remain in the table. That is, the server device 1 determines whether or not a message remains in the database 3 instead of the transmission buffer in step S304 in the flowchart of FIG. When it is determined that the message remains (S304: YES), the control unit 10 uses the message remaining in the database 3 as a client device 2 that has already established a session with another server device 1. Is stored (moved) in the database 3 ("store_target_broker_user" table) as a message (stored message and delivery destination information via the broker) that should have been sent to (S305).

ダウンしたブローカであるサーバ装置1は自身のダウンを検知することはできず、ネットワークコントローラの送信バッファにおける一時記憶情報も失われる。したがってダウンしたサーバ装置1は、図24のフローチャートにおけるステップS304及びステップS305で示したような残存メッセージの退避保存処理はできない。またダウンしたサーバ装置1は、ダウン中に図28のフローチャートにおけるステップS211からS214に示した切断中のメッセージの退避保存を行なうことはできない。したがって再起動したサーバ装置1は、他のサーバ装置1がデータベース3に記憶したメッセージを参照して、ダウン中に送信されたメッセージをクライアント装置2へ向けて送信する。   The server apparatus 1 that is a down broker cannot detect its own down, and the temporary storage information in the transmission buffer of the network controller is also lost. Therefore, the server apparatus 1 that has been down cannot perform the saving and saving process for the remaining messages as shown in steps S304 and S305 in the flowchart of FIG. In addition, the server apparatus 1 that has been down cannot save and save the message that is being disconnected shown in steps S211 to S214 in the flowchart of FIG. Therefore, the restarted server device 1 refers to the message stored in the database 3 by the other server device 1 and transmits the message transmitted during down to the client device 2.

図34は、サーバ装置1の起動時の処理手順の一例を示すフローチャートである。サーバ装置1の制御部10は、起動するとクライアント装置2及び他のサーバ装置1夫々とセッションを確立し(ステップS401)、確立したセッションにて他のサーバ装置1と同期処理を実行する(ステップS402)。   FIG. 34 is a flowchart illustrating an example of a processing procedure when the server apparatus 1 is activated. When activated, the control unit 10 of the server device 1 establishes a session with each of the client device 2 and the other server device 1 (step S401), and executes synchronization processing with the other server device 1 in the established session (step S402). ).

サーバ装置1の制御部10は、自身に接続しているとして一時記憶しているサブスクライバであるクライアント装置2の識別情報と、データベース3に記憶されている各クライアント装置2の接続先情報(「connections 」)とを照合する(ステップS403)。ステップS403の処理は、図24のフローチャートに示したステップS308の処理と同様である。   The control unit 10 of the server apparatus 1 identifies the identification information of the client apparatus 2 that is a subscriber temporarily stored as being connected to itself, and the connection destination information (“connections” of each client apparatus 2 stored in the database 3. ]) Is collated (step S403). The process of step S403 is the same as the process of step S308 shown in the flowchart of FIG.

サーバ装置1の制御部10は、ステップS403の照合の結果、自身に通信接続しており、状態情報がonlineであるクライアント装置2(複数存在する場合は夫々)について、データベース3に記憶されている接続先の情報中に基づき、接続先が自身であるか否かを判断する(ステップS404)。   As a result of the collation in step S403, the control unit 10 of the server apparatus 1 is connected to itself and is stored in the database 3 for the client apparatus 2 (each of which has a plurality of status information) whose status information is online. Based on the connection destination information, it is determined whether or not the connection destination is itself (step S404).

サーバ装置1の制御部10は、自身でない(S404:NO)、制御部10は、自身に接続しているクライアント装置2の状態情報の内、対象のサブスクライバであるクライアント装置2の情報を削除し(ステップS405)、起動時の処理を終了し、正常運用時の処理へ移行する(図4又は図20等参照)。   The control unit 10 of the server device 1 is not itself (S404: NO), and the control unit 10 deletes the information of the client device 2 that is the target subscriber from the status information of the client device 2 connected to itself. (Step S405), the process at the time of starting is terminated, and the process proceeds to the process at the time of normal operation (see FIG. 4 or FIG. 20).

サーバ装置1の制御部10は、ステップS404で自身であると判断した場合(S404:YES)、通信接続しているクライアント装置2に対し、他のサーバ装置1により、自身を経由して送信されるメッセージであったことを示す情報(ブローカ経由の配信先情報)を、データベース3(「store_target_broker_user」テーブル)から抽出する(ステップS406)。更に制御部10は、通信接続しているサブスクライバであるクライアント装置2向けにデータベース3(「store 」及び「store_target」テーブル)に記憶しているメッセージを抽出する(ステップS407)。制御部10は、ステップS406及びS407で抽出した情報に基づくpublish メッセージを、記憶した時刻の順にクライアント装置2へ送信する(ステップS408)。その後制御部10は、送信先のクライアント装置2からpubackメッセージを受信し(ステップS409)、これを受信できた場合に、配信先情報、並びに保存してあったメッセージを削除する(ステップS410)。publish メッセージの送信により起動時の処理は終了する。なおステップS406及びS407で情報が抽出されない場合は勿論、ステップS408−S410の処理は実行されない。   When the control unit 10 of the server apparatus 1 determines that it is itself in step S404 (S404: YES), it is transmitted to the client apparatus 2 that is in communication connection by another server apparatus 1 via itself. Information (distribution destination information via broker) is extracted from the database 3 ("store_target_broker_user" table) (step S406). Further, the control unit 10 extracts a message stored in the database 3 (“store” and “store_target” table) for the client apparatus 2 that is a subscriber connected for communication (step S407). The control unit 10 transmits a publish message based on the information extracted in steps S406 and S407 to the client device 2 in the order of the stored times (step S408). After that, the control unit 10 receives the puback message from the destination client device 2 (step S409), and when receiving this, deletes the distribution destination information and the stored message (step S410). The start-up process is completed by sending the publish message. In addition, when information is not extracted by step S406 and S407, the process of step S408-S410 is not performed.

図34のフローチャートに示した処理を、切断箇所別に説明する。
(3.2.1)パブリッシャ・ブローカ間
図23の説明図に示したパブリッシャからサブスクライバまでの間のメッセージを、2つのブローカが仲介する場合に、パブリッシャ寄りに存在するブローカであるサーバ装置1(b1)がダウンする場合におけるパブリッシャ・ブローカ間のセッションについて説明する。この場合は、パブリッシャであるクライアント装置2(p1)は、改めて通信接続したブローカであるサーバ装置1(b1)へ新たなパケットIDにてpublish メッセージを再送することでQoS =1が実現可能である。
The process shown in the flowchart of FIG. 34 will be described for each cutting location.
(3.2.1) Between Publisher and Broker When the message between the publisher and the subscriber shown in the explanatory diagram of FIG. 23 is mediated by the two brokers, the server device 1 (broker that exists near the publisher) ( Explain the session between publisher and broker when b1) goes down. In this case, the client device 2 (p1), which is the publisher, can realize QoS = 1 by retransmitting the publish message with a new packet ID to the server device 1 (b1), which is the broker that is newly connected for communication. .

なお、ブローカであるサーバ装置1(b1)は、パブリッシャであるクライアント装置2(p1)からpublish メッセージが送信され、これをサーバ装置1(b2)へ送信する前に、データベース3(「store_target_broker 」テーブル)にそのメッセージを記憶している。このときサーバ装置1(b1)は、クライアント装置2(p1)からpublish メッセージを受信したときに使用されていたパケットIDをデータベース3にイベントログとして記憶しておき、図24及び図34のフローチャートに示した処理手順で再起動後にやり取りを継続してもよい。サーバ装置1(b1)が、他のサーバ装置1全て(b2)からpubackメッセージを受信する前にダウンした場合、ダウンしている間にサーバ装置1(b2)が切断を検知し、データベース3(「store_target_broker 」テーブル)に記憶してあった配信先情報を、自身(b1)を経由して送信されるメッセージであったことを示す情報としてデータベース3(「store_target_broker_user」テーブル)へ移動できる。このときサーバ装置1(b1)は、データベース3への移動を契機にパブリッシャであるクライアント装置2(p1)へ向けてpubackメッセージを送信する。再確立後、サーバ装置1(b2)は、データベース3(「store_target_broker_user」テーブル)に記憶してある自身(b2)から送信されるメッセージであることを示す情報に基づき、クライアント装置2(s1)向けのpublish メッセージの送信を実行する。   The server device 1 (b1) serving as the broker receives a publish message from the client device 2 (p1) serving as the publisher, and before sending this message to the server device 1 (b2), the database 3 (“store_target_broker” table ) Is stored in the message. At this time, the server apparatus 1 (b1) stores the packet ID used when the publish message is received from the client apparatus 2 (p1) as an event log in the database 3, and the flowcharts of FIGS. The exchange may be continued after the restart according to the processing procedure shown. When the server device 1 (b1) goes down before receiving the puback message from all the other server devices 1 (b2), the server device 1 (b2) detects disconnection while it is down, and the database 3 ( The delivery destination information stored in the “store_target_broker” table) can be moved to the database 3 (“store_target_broker_user” table) as information indicating that the message is a message transmitted via itself (b1). At this time, the server device 1 (b1) transmits a puback message to the client device 2 (p1), which is the publisher, in response to the movement to the database 3. After the re-establishment, the server device 1 (b2) is directed to the client device 2 (s1) based on information indicating that the message is a message transmitted from itself (b2) stored in the database 3 (“store_target_broker_user” table). Execute publish message transmission.

(3.2.2)ブローカ・サブスクライバ間
次に、サブスクライバ寄りに存在するブローカであるサーバ装置1(b2)がダウンするケースにおけるブローカ・サブスクライバ間のセッションについて説明する。図23の説明図に示したセッションFに対応する。図35は、ブローカであるサーバ装置1(b2)がダウンした場合の処理を示す図である。詳細には、サーバ装置1(b2)が、クライアント装置2(s1)へpublish メッセージを送信し、pubackメッセージを受信する前にダウンした場合の例を示す。なお図35の例では、サーバ装置1(b1)へのpubackメッセージが送信された後とする。
(3.2.2) Between Brokers and Subscribers Next, a session between brokers and subscribers in a case where the server apparatus 1 (b2), which is a broker existing near the subscriber, goes down will be described. This corresponds to the session F shown in the explanatory diagram of FIG. FIG. 35 is a diagram showing processing when the server device 1 (b2) as the broker goes down. Specifically, an example is shown in which the server device 1 (b2) is down before sending a publish message to the client device 2 (s1) and receiving a puback message. In the example of FIG. 35, it is assumed that the puback message is transmitted to the server apparatus 1 (b1).

図35の例では、ブローカであるサーバ装置1(b1)へのpubackメッセージが送信された後にダウンによってセッションが切断される。サーバ装置1(b1、保証ありで起動)が、サーバ装置1(b2)に向けて(20)のタイミングでpublish メッセージ送信する前にデータベース3に記憶したメッセージ及び送信先(「store 」及び「store_target_broker 」テーブル)の情報は削除されている。サーバ装置1(b2)がダウン保証ありで再起動した場合に、(30)のタイミングでpublish メッセージを送信する前にデータベース3(「store 」及び「store_target」テーブル)に記憶していたメッセージ及び配信先情報に基づき、クライアント装置2(s1)へpublish メッセージが再送される(図11同様)。このときパケットIDがデータベース3に記憶していた情報から参照されて送信される。クライアント装置2(s1)からそのパケットIDにてpubackメッセージが送信されることでデータベース3(「store 」及び「store_target」テーブル)からは情報が削除される。   In the example of FIG. 35, after the puback message is transmitted to the server device 1 (b1) which is the broker, the session is disconnected due to the down. The message stored in the database 3 and the transmission destination ("store" and "store_target_broker" before the server apparatus 1 (b1, activated with guarantee) transmits the publish message to the server apparatus 1 (b2) at the timing (20). "Table) information has been deleted. Messages and distribution stored in database 3 ("store" and "store_target" tables) before sending publish message at timing (30) when server device 1 (b2) is restarted with down guarantee Based on the destination information, the publish message is retransmitted to the client apparatus 2 (s1) (same as in FIG. 11). At this time, the packet ID is referred to from the information stored in the database 3 and transmitted. Information is deleted from the database 3 (“store” and “store_target” tables) by transmitting a puback message with the packet ID from the client device 2 (s1).

(3.2.3)ブローカ・ブローカ間
次に、サブスクライバ寄りに存在するブローカであるサーバ装置1(b2)がダウンするケースにおけるブローカ間のセッションについて説明する。図36は、ブローカであるサーバ装置1(b2)がダウンした場合の処理を示す図である。詳細には、サーバ装置1(b2)が、ブローカであるサーバ装置1(b1)からのpublish メッセージを受信する前後、クライアント装置2(s1)へpublish メッセージへの送信を行なう前にダウンした場合の例を示す。
(3.2.3) Between Brokers and Brokers Next, a session between brokers in a case where the server apparatus 1 (b2), which is a broker existing near the subscriber, goes down will be described. FIG. 36 is a diagram showing processing when the server device 1 (b2) as the broker goes down. Specifically, when server device 1 (b2) goes down before and after receiving the publish message from broker server device 1 (b1) and before sending the publish message to client device 2 (s1). An example is shown.

図36の例では、サーバ装置1(b1、保証ありで起動)がサーバ装置1(b2)に向けて(20)のタイミングでpublish メッセージを送信する前に、データベース3に記憶したメッセージ及び送信先(「store 」及び「store_target_broker 」テーブル)の情報は残っている。サーバ装置1(b1)は、サーバ装置1(b2)のダウンによるセッションGが切断されたことを検知すると(図24のステップS301)、サーバ装置1(b2)とセッションを確立しているクライアント装置2(s1)へ送信されていたはずのメッセージとしてデータベース3(「store_target_broker_user」テーブル)にブローカ経由の配信先情報を保存(移動)する(S305)。そしてサーバ装置1(b1)は、データベース3に保存したことによってパブリッシャであるクライアント装置2(p1)へpuback メッセージを送信する(S306)。   In the example of FIG. 36, the message stored in the database 3 and the transmission destination before the server apparatus 1 (b1, activated with guarantee) transmits the publish message to the server apparatus 1 (b2) at the timing (20). Information of ("store" and "store_target_broker" table) remains. When the server apparatus 1 (b1) detects that the session G is disconnected due to the server apparatus 1 (b2) being down (step S301 in FIG. 24), the client apparatus that has established a session with the server apparatus 1 (b2) The distribution destination information via the broker is stored (moved) in the database 3 (“store_target_broker_user” table) as a message that should have been transmitted to 2 (s1) (S305). Then, the server device 1 (b1) transmits a puback message to the client device 2 (p1), which is the publisher, by storing in the database 3 (S306).

図37は、図36に示した状態の後、サーバ装置1(b2)が起動した後に行なわれる処理の例を示す図である。サーバ装置1(b1, b2)は夫々相互にセッションの確立、同期処理及び照合等の処理を行なう(図24のS307からS309、図34のS401からS403)。再起動したサーバ装置1(b2)は、クライアント装置2(s1)について、接続先は自身であると判断する(S404:YES)。サーバ装置1(b2)は、接続先を自身とするクライアント装置2(s1)へ送信されていたはずのメッセージ(ブローカ経由の配信先情報)をデータベース3(「store_target_broker_user」テーブル)から抽出し(S406)、新たなパケットID(「0x133 」)を用いてタイミング(50)で送信する(S408)。このときサーバ装置1(b2)によって再度、データベース3(「store 」及び「store_target」テーブル)に保存メッセージ及び配信先情報(user_id=s1, packet_id=0x133, store_id=789, already_sent=false, qos=1)が記憶される。その後(60)のタイミングにてクライアント装置2(s1)からpubackメッセージが送信され、サーバ装置1(b2)がこれを受信する(S409)ことで、この保存メッセージ及び配信先情報が削除されている(S410)。   FIG. 37 is a diagram showing an example of processing performed after the server device 1 (b2) is started after the state shown in FIG. The server devices 1 (b1, b2) perform processing such as session establishment, synchronization processing, and collation with each other (S307 to S309 in FIG. 24, S401 to S403 in FIG. 34). The restarted server device 1 (b2) determines that the connection destination is the client device 2 (s1) (S404: YES). The server device 1 (b2) extracts a message (distribution destination information via the broker) that should have been transmitted to the client device 2 (s1) whose connection destination is itself from the database 3 (“store_target_broker_user” table) (S406). ), And transmits at timing (50) using the new packet ID (“0x133”) (S408). At this time, the server device 1 (b2) again stores the stored message and distribution destination information (user_id = s1, packet_id = 0x133, store_id = 789, already_sent = false, qos = 1) in the database 3 (“store” and “store_target” table). ) Is stored. Thereafter, the puback message is transmitted from the client apparatus 2 (s1) at the timing (60), and the server apparatus 1 (b2) receives this message (S409), so that the stored message and the delivery destination information are deleted. (S410).

このようにして、ブローカであるサーバ装置1がセッションの切断のみならずダウンした場合であっても、パブリッシャからQoS =1を指定して送信されたメッセージについて、サブスクライバまでの到達を、QoS =1(「At least Once 」(最低1回、1回以上届く))で保証することが可能である。   In this way, even when the server device 1 as the broker goes down as well as disconnecting the session, the message sent from the publisher with QoS = 1 specified can reach the subscriber with QoS = 1 (“At least Once”).

(4)QoS =2、ブローカダウン保証外の動作
次に、ブローカがダウンした場合にメッセージの到達を保証しないという前提において、パブリッシャであるクライアント装置2からQoS =2を指定してpublish メッセージが送信される場合の処理について説明する。なお以下の説明では、当該メッセージのトピックを指定しているサブスクライバであるクライアント装置2が、トピック指定時にQoS として「2」を指定している場合の当該サブスクライバまでのメッセージの到達について説明する。なお、同一のメッセージのサブスクライバであって、トピック指定時に「0」を指定しているサブスクライバへのメッセージ送信は(1)で述べたようにpublish メッセージを1回送信するのみで処理が終了するので説明を省略する。また、トピック指定時に「1」を指定しているサブスクライバへのメッセージの送信は(2)で述べたpubackメッセージの順序性をpubrecメッセージに読み替えた内容に基づき行なわれる。つまり原則的に、他のサーバ装置1全てからpubackメッセージを受信するまで、送信元へpubrecメッセージを返さないという制御が行なわれる。
(4) QoS = 2, operation not guaranteed by broker down Next, publish message is sent from client device 2 as publisher specifying QoS = 2 on the assumption that message arrival is not guaranteed when the broker goes down The processing when this is done will be described. In the following description, the message arrival to the subscriber when the client device 2 that is the subscriber who designates the topic of the message has designated “2” as the QoS when the topic is designated will be described. Note that message transmission to subscribers of the same message who have specified “0” at the time of specifying a topic is completed by only transmitting the publish message once as described in (1). Description is omitted. In addition, transmission of a message to a subscriber who designates “1” when a topic is designated is performed based on the content obtained by replacing the order of the puback message described in (2) with a pubrec message. That is, in principle, control is performed such that the pubrec message is not returned to the transmission source until the puback message is received from all the other server apparatuses 1.

(4.1)正常運用時
QoS =2で送信されるメッセージを保証する場合、ブローカであるサーバ装置1は、パケットID対応情報(pidmap)を記憶して利用する。図1に示したように通信システム100では、複数のブローカ(大抵は1又は2台)がメッセージの配信を仲介する。パブリッシャであるクライアント装置2が接続しているブローカと、サブスクライバであるクライアント装置2が接続しているブローカとが異なる場合、即ちメッセージの送受信に2台以上のブローカが存在する場合には、メッセージはこのブローカ間のセッションを経由する。図3に示したようにサーバ装置1はMQTTモデルに準拠し、セッション毎に、パケットIDをキーとしてメッセージをやり取りする。本開示のサーバ装置1は、自身が確立するセッションに関し、同一のメッセージの送信のために異なるセッション間で使用されたパケットIDの対応関係をパケットID対応情報(pidmap)として記憶する。正常時からパケットID対応情報を記憶しておくことにより、後述するように、メッセージのやり取りの中途でセッションが切断した場合、又はサーバがダウンした場合であっても直前の状態に復帰させることが可能になる。
(4.1) During normal operation
When guaranteeing a message transmitted with QoS = 2, the server device 1 as a broker stores and uses packet ID correspondence information (pidmap). As shown in FIG. 1, in the communication system 100, a plurality of brokers (usually one or two) mediate message distribution. If the broker to which the client device 2 that is the publisher is connected is different from the broker to which the client device 2 that is the subscriber is connected, that is, if there are two or more brokers for sending and receiving messages, the message is It goes through a session between these brokers. As shown in FIG. 3, the server apparatus 1 conforms to the MQTT model, and exchanges messages using the packet ID as a key for each session. The server device 1 according to the present disclosure stores, as packet ID correspondence information (pidmap), a correspondence relationship between packet IDs used between different sessions for transmission of the same message regarding a session established by itself. By storing packet ID correspondence information from the normal time, as described later, even when the session is disconnected in the middle of message exchange or when the server is down, it is possible to return to the previous state. It becomes possible.

図38は、QoS =2におけるパケットID対応情報の説明図である。なお図38の説明図では、パブリッシャであるクライアント装置2と該パブリッシャから送信されるメッセージのトピックを指定トピックとしているサブスクライバであるクライアント装置2との間に、2つのブローカが介在する場合の接続構成にて各サーバ装置1で記憶される情報の例を示している。図38では、クライアント装置2(p1)がパブリッシャとしてサーバ装置1(b1)に通信接続し(セッションJ)、同じサーバ装置1(b1)にクライアント装置2(s2)がサブスクライバとして通信接続している(セッションM)。クライアント装置2(s1)は、サブスクライバとしてサーバ装置1(b2)に通信接続している(セッションK)。2つのブローカであるサーバ装置1(b1, b2)間も、通信接続されている(セッションL)。図38の例においてクライアント装置2(p1)から送信されるメッセージは、セッションJ及びセッションMを経由してクライアント装置2(s2)へ到達し、セッションJ、セッションL及びセッションKを経由してクライアント装置2(s1)へ到達する。   FIG. 38 is an explanatory diagram of packet ID correspondence information in QoS = 2. In the explanatory diagram of FIG. 38, a connection configuration in the case where two brokers are interposed between the client device 2 that is a publisher and the client device 2 that is a subscriber whose designated topic is the topic of a message transmitted from the publisher. The example of the information memorize | stored in each server apparatus 1 is shown. In FIG. 38, the client device 2 (p1) is connected to the server device 1 (b1) as a publisher (session J), and the client device 2 (s2) is connected to the same server device 1 (b1) as a subscriber. (Session M). The client device 2 (s1) is communicatively connected to the server device 1 (b2) as a subscriber (session K). The server apparatuses 1 (b1, b2), which are two brokers, are also connected for communication (session L). In the example of FIG. 38, the message transmitted from the client device 2 (p1) reaches the client device 2 (s2) via the session J and the session M, and the client via the session J, the session L, and the session K. The device 2 (s1) is reached.

サーバ装置1は夫々、3種類のパケットID対応情報を一時記憶部13に記憶している。3種類のパケットID対応情報は第1に、クライアント装置2から自身であるサーバ装置1へのメッセージにおけるパケットIDと(userからの受信の意味で「u 」)、自身であるサーバ装置1からクライアント装置2へのメッセージにおけるパケットIDと(userへの送信の意味で「u 」)の対応関係(pid_map_u2u )を含む。第2に、クライアント装置2から自身であるサーバ装置1へのメッセージにおけるパケットIDと(userからの受信の意味で「u 」)、自身であるサーバ装置1から他のサーバ装置1へのメッセージにおけるパケットIDと(brokerへの送信の意味で「b 」)の対応関係(pid_map_u2b )を含む。第3に、他のサーバ装置1から自身であるサーバ装置1へのメッセージにおけるパケットIDと(brokerからの受信の意味で「b 」)、自身であるサーバ装置1からクライアント装置2へのメッセージにおけるパケットIDと(userへの送信の意味で「u 」)の対応関係(pid_map_b2u )を含む。夫々のパケットID対応情報は、自身へのメッセージの送信者の識別情報([source_user(broker)_id])、自身からのメッセージの受信者の識別情報([target_user(broker)_id])、前記送信者からのパケットID([source_pid]、図中では[s_pid]で示す)、前記受信者向けのパケットID([target_pid]、図中では[t_pid]で示す)、メッセージの送信の完了を示す論理値([sent])を含む。   Each of the server devices 1 stores three types of packet ID correspondence information in the temporary storage unit 13. First, the three types of packet ID correspondence information include the packet ID in the message from the client device 2 to the server device 1 that is the client device 2 ("u" in the meaning of reception from the user), and the client device 2 from the server device 1 that is itself. It includes the correspondence (pid_map_u2u) between the packet ID in the message to the apparatus 2 and “u” in the sense of transmission to the user. Second, the packet ID in the message from the client device 2 to the server device 1 that is itself (“u” in the sense of reception from the user), and the message from the server device 1 that is itself to the other server device 1 It includes the correspondence (pid_map_u2b) between the packet ID and ("b" in the sense of transmission to the broker). Third, the packet ID in the message from the other server device 1 to the server device 1 itself (“b” in the meaning of reception from the broker), and the message from the server device 1 to the client device 2 It includes the correspondence (pid_map_b2u) between the packet ID and ("u" in the sense of transmission to the user). Each packet ID correspondence information includes identification information of the sender of the message to itself ([source_user (broker) _id]), identification information of the receiver of the message from itself ([target_user (broker) _id]), and the transmission Packet ID from the sender ([source_pid], indicated by [s_pid] in the figure), packet ID for the receiver ([target_pid], indicated by [t_pid] in the figure), and logic indicating completion of message transmission Contains the value ([sent]).

図38に示す接続構成の場合、ブローカであるサーバ装置1(b1)は、パブリッシャであるクライアント装置2(p1)から送信されるpublish メッセージについて3種類のパケットID対応情報の内、次の2つのパケットID対応情報を用いる。1つは、クライアント装置2(p1)からのメッセージのパケットIDと、自身に通信接続しているサブスクライバであるクライアント装置2(s2)へのメッセージのパケットIDとの対応関係のためのパケットID対応情報(pid_map_u2u )である。1つは、クライアント装置2(p1)からのメッセージのパケットIDと、自身と通信接続している他のブローカであるサーバ装置1(b2)へのメッセージのパケットIDとの対応関係のためのパケットID対応情報(pid_map_u2b )である。図38に示す例では、サーバ装置1(b1)は、パブリッシャであるクライアント装置2(p1)からのパケットIDと、サブスクライバであるクライアント装置2(s2)へのメッセージのパケットIDとの対応関係のための第1のパケットID対応情報(pid_map_u2u )(source_user_id=p1, target_user_id=s2)を用いる。同様にして、サーバ装置1(b1)は、パブリッシャであるクライアント装置2(p1)からのパケットIDと、他のブローカであるサーバ装置1(b2)へのメッセージのパケットIDとの対応関係のための第2のパケットID対応情報(pid_map_u2b )(source_user_id=p1, target_broker_id=b2)を用いる。   In the case of the connection configuration shown in FIG. 38, the server device 1 (b1) serving as the broker has the following two types of packet ID correspondence information for the publish message transmitted from the client device 2 (p1) serving as the publisher. Packet ID correspondence information is used. One is the packet ID correspondence for the correspondence between the packet ID of the message from the client device 2 (p1) and the packet ID of the message to the client device 2 (s2) that is a subscriber connected to the client device 2 (p1). Information (pid_map_u2u). One is a packet for correspondence between the packet ID of the message from the client device 2 (p1) and the packet ID of the message to the server device 1 (b2), which is another broker connected to itself. ID correspondence information (pid_map_u2b). In the example shown in FIG. 38, the server device 1 (b1) has a correspondence relationship between the packet ID from the client device 2 (p1) as a publisher and the packet ID of a message to the client device 2 (s2) as a subscriber. First packet ID correspondence information (pid_map_u2u) (source_user_id = p1, target_user_id = s2) is used. Similarly, the server device 1 (b1) has a correspondence between the packet ID from the client device 2 (p1) as a publisher and the packet ID of a message to the server device 1 (b2) as another broker. Second packet ID correspondence information (pid_map_u2b) (source_user_id = p1, target_broker_id = b2) is used.

同様にして図38に示す接続構成では、サーバ装置1(b2)は、他のサーバ装置1(b1)からのメッセージのパケットIDと、自身に通信接続しているサブスクライバであるクライアント装置2(s1)へのメッセージのパケットIDとの対応関係のためのパケットID対応情報(pid_map_b2u )(source_broker_id=b1, target_user_id=s1)を用いる。   Similarly, in the connection configuration shown in FIG. 38, the server apparatus 1 (b2) has a packet ID of a message from the other server apparatus 1 (b1) and a client apparatus 2 (s1) that is a subscriber connected to itself. The packet ID correspondence information (pid_map_b2u) (source_broker_id = b1, target_user_id = s1) is used for the correspondence with the packet ID of the message.

図39は、パケットID対応情報を用いたメッセージの処理手順の一例を示すフローチャートである。なお図39のフローチャートに示す処理手順は、図4のフローチャートに示した手順の内のステップS9の詳細に対応する。   FIG. 39 is a flowchart illustrating an example of a message processing procedure using packet ID correspondence information. The processing procedure shown in the flowchart of FIG. 39 corresponds to the details of step S9 in the procedure shown in the flowchart of FIG.

サーバ装置1の制御部10は、パブリッシャとして通信接続を確立している1又は複数のクライアント装置2から、又は他のサーバ装置1からpublish メッセージを受信したか否かを判断する(ステップS501)。受信していないと判断された場合(S501:YES)、制御部10は処理をステップS501へ戻す。   The control unit 10 of the server apparatus 1 determines whether or not a publish message has been received from one or a plurality of client apparatuses 2 that have established a communication connection as a publisher, or from another server apparatus 1 (step S501). If it is determined that the data has not been received (S501: YES), the control unit 10 returns the process to step S501.

制御部10は、受信したと判断した場合(S501:YES)、受信したpublish メッセージのパケットIDを特定する(ステップS502)。制御部10は、受信したpublish メッセージのトピックを抽出し(ステップS503)、抽出されたトピックについての送信先に他のサーバ装置1が含まれるか否かを判断する(ステップS504)。   If the control unit 10 determines that it has been received (S501: YES), it specifies the packet ID of the received publish message (step S502). The control unit 10 extracts the topic of the received publish message (step S503), and determines whether another server device 1 is included in the transmission destination for the extracted topic (step S504).

ステップS503にて他のサーバ装置1が含まれないと判断された場合(S504:NO)、制御部10は、ステップS501で受信したpublish メッセージについて、抽出されたトピックを指定して自身に通信接続しているサブスクライバであるクライアント装置2を受信者とするレコードを、記憶しているパケットID対応情報(pid_map_u2u )から検索できたか否か判断する(ステップS505)。ステップS505にて制御部10は、送信者([source_user(broker)_id])、受信者([target_user(broker)_id])及びステップS502で特定したパケットID([source_pid])でレコードを検索する。   When it is determined in step S503 that the other server device 1 is not included (S504: NO), the control unit 10 specifies the extracted topic for the publish message received in step S501, and establishes communication connection to itself. It is determined whether or not a record having the client device 2 as a receiver as a receiver can be retrieved from the stored packet ID correspondence information (pid_map_u2u) (step S505). In step S505, the control unit 10 searches for a record using the sender ([source_user (broker) _id]), the receiver ([target_user (broker) _id]), and the packet ID ([source_pid]) specified in step S502. .

ステップS505で検索できなかったと判断された場合(S505:NO)、新規のメッセージであるから制御部10は、受信者とのセッションにおけるパケットIDを採番し(ステップS506)、レコードを作成して記憶する(ステップS507)。制御部10は、ステップS506で採番したパケットIDを使用して、サブスクライバであるクライアント装置2へ向けてステップS501で受信したpublish メッセージを送信する(ステップS508)。   If it is determined in step S505 that the search could not be performed (S505: NO), since it is a new message, the control unit 10 assigns a packet ID in the session with the recipient (step S506), and creates a record. Store (step S507). The control unit 10 transmits the publish message received in step S501 to the client device 2 that is a subscriber, using the packet ID numbered in step S506 (step S508).

検索できたと判断された場合(S505:YES)、制御部10は、レコードにおけるメッセージの送信完了が完了を示しているか否かを判断する(ステップS509)。完了していないと判断された場合(S509:NO)、publish メッセージを再送する(ステップS508)。なおステップS508において、検索されたレコードに受信者向けのパケットIDが存在する場合は、そのパケットIDを使用して送信し、存在しない場合はここでパケットIDを採番して送信するとよい。   When it is determined that the search has been completed (S505: YES), the control unit 10 determines whether or not the message transmission completion in the record indicates completion (step S509). If it is determined that it has not been completed (S509: NO), the publish message is retransmitted (step S508). In step S508, if there is a packet ID for the receiver in the retrieved record, the packet ID is used for transmission. If there is no packet ID, the packet ID is numbered and transmitted here.

送信が完了していると判断された場合(S509:YES)、制御部10は送信処理を省略して次のステップS510)へ処理を進める。   When it is determined that the transmission is completed (S509: YES), the control unit 10 skips the transmission process and proceeds to the next step S510).

なおステップS508において制御部10は、送信先に、keep接続を選択しており且つセッションが切断中であるクライアント装置2が存在する場合には、送信先をデータベース3とする。送信先をデータベース3とする場合は、ステップS505のパケットIDは採番できないので、パケットIDなしでパケットID対応情報を記憶するとよい(S507)。   In step S508, the control unit 10 sets the transmission destination as the database 3 when there is a client device 2 that has selected keep connection and the session is disconnected. When the transmission destination is the database 3, since the packet ID in step S505 cannot be numbered, the packet ID correspondence information may be stored without the packet ID (S507).

続いて制御部10は、受信したpublish メッセージの送信元(パブリッシャ又は他のサーバ装置1)へpubrecメッセージを返す(ステップS510)。制御部10は、publish メッセージの受信者からpubrecメッセージを受信したか否かを判断する(ステップS511)。受信していないと判断された場合(S511:NO)、制御部10は処理をステップS511へ戻し、受信したと判断されるまで待機する。受信したと判断された場合(S511:YES)、制御部10は、パケットID対応情報のレコードをpubrecメッセージの送信元を受信者の識別情報([target_user(broker)_id])及びpubrecメッセージのパケットID([target_pid])で検索し、検索されたレコードについて、メッセージが送信完了であるとして更新する(ステップS512)。   Subsequently, the control unit 10 returns a pubrec message to the transmission source (publisher or other server apparatus 1) of the received publish message (step S510). The control unit 10 determines whether a pubrec message has been received from the recipient of the publish message (step S511). If it is determined that it has not been received (S511: NO), the control unit 10 returns the process to step S511 and waits until it is determined that it has been received. When it is determined that the packet is received (S511: YES), the control unit 10 uses the packet ID correspondence information record as the sender of the pubrec message, the recipient identification information ([target_user (broker) _id]), and the pubrec message packet. The search is performed using the ID ([target_pid]), and the retrieved record is updated on the assumption that the message has been transmitted (step S512).

次に制御部10は、pubrelメッセージをpublish メッセージの送信者から受信したか否かを判断する(ステップS513)。受信していないと判断された場合(S513:NO)、制御部10は処理をステップS513へ戻し、受信したと判断されるまで待機する。受信したと判断された場合(S513:YES)、制御部10は、パケットID対応情報のレコードを送信者のpubrelメッセージの送信者の識別情報([source_user(broker)_id])及びpubrelメッセージのパケットID([source_pid])で検索し、検索されたレコードを削除し(ステップS514)、1つのpublish メッセージの配信処理を終了する。   Next, the control unit 10 determines whether or not the pubrel message has been received from the sender of the publish message (step S513). If it is determined that it has not been received (S513: NO), the control unit 10 returns the process to step S513 and waits until it is determined that it has been received. When it is determined that the packet is received (S513: YES), the control unit 10 records the packet ID correspondence information in the sender identification information ([source_user (broker) _id]) of the sender pubrel message and the packet of the pubrel message. Search by ID ([source_pid]), delete the searched record (step S514), and terminate the distribution process of one publish message.

ステップS504にて他のサーバ装置1が含まれると判断された場合(S504:YES)、制御部10は、他のサーバ装置1に向けて、上述のステップS505からS509に示した処理と同様の処理S515からS519を、記憶しているパケットID対応情報(pid_map_u2b )に対して行なう。なお、ステップS518において制御部10は、他のサーバ装置1以外に、抽出されたトピックを指定して自身に通信接続しているサブスクライバであるクライアント装置2へ送信する場合には、同様にしてpublish メッセージを送信する(S518)。   When it is determined in step S504 that the other server device 1 is included (S504: YES), the control unit 10 is directed to the other server device 1 in the same manner as the processing described in steps S505 to S509 described above. Processes S515 to S519 are performed on the stored packet ID correspondence information (pid_map_u2b). In step S518, when the control unit 10 transmits to the client device 2 that is a subscriber that is in communication connection with the specified topic in addition to the other server device 1, it is similarly published. A message is transmitted (S518).

他のサーバ装置が送信先に含まれる場合、制御部10はステップS518の後に、他のサーバ装置1全てからpubrecメッセージを受信するまで、pubrecメッセージを受信したか否か判断する(ステップS520)。受信していないと判断された場合(S520:NO)、制御部10は処理をステップS520へ戻し、次のステップS521には進まない。受信したと判断された場合(S520:YES)、制御部10は、パケットID対応情報のレコードをpubrecメッセージの送信元を受信者の識別情報([target_user(broker)_id])及びpubrecメッセージのパケットID([target_pid])で検索し、検索されたレコードについて、メッセージが送信完了であるとして更新する(ステップS521)。そして他のサーバ装置1全てからpubrecメッセージを受信したか否かを判断する(ステップS522)。全てから受信していないと判断された場合(S522:NO)、制御部10は処理をステップS520へ戻し、他のpubrecメッセージを受信するまで次のステップS523の処理は行なわない。ステップS522にて、他のサーバ装置1全てからpubrecメッセージを受信したと判断された場合(S522:YES)、制御部10は、自身に通信接続しているクライアント装置2からpubrecメッセージを受信していなくとも、この場合はステップS523へ処理を進め、クライアント装置2からのpubrecメッセージについては個別に処理する。   When another server device is included in the transmission destination, the control unit 10 determines whether or not the pubrec message has been received until the pubrec message is received from all the other server devices 1 after step S518 (step S520). When it is determined that the data has not been received (S520: NO), the control unit 10 returns the process to step S520 and does not proceed to the next step S521. When it is determined that the packet is received (S520: YES), the control unit 10 uses the packet ID correspondence information record as the sender of the pubrec message, the identification information of the receiver ([target_user (broker) _id]), and the packet of the pubrec message. The search is performed using the ID ([target_pid]), and the retrieved record is updated assuming that the message has been transmitted (step S521). Then, it is determined whether or not the pubrec message has been received from all the other server devices 1 (step S522). If it is determined that the message has not been received from all (S522: NO), the control unit 10 returns the process to step S520 and does not perform the process of the next step S523 until another pubrec message is received. If it is determined in step S522 that the pubrec message has been received from all the other server devices 1 (S522: YES), the control unit 10 has received the pubrec message from the client device 2 that is communicatively connected to itself. In this case, the process proceeds to step S523, and the pubrec message from the client apparatus 2 is individually processed.

ステップS522にて他のサーバ装置1全てからpubrecメッセージを受信したと判断された場合(S522:YES)、制御部10は、受信したpublish メッセージの送信元(パブリッシャ又は他のサーバ装置1)へpubrecメッセージを返す(ステップS523)。続けて制御部10は、pubrelメッセージをpublish メッセージの送信者から受信したか否かを判断する(ステップS524)。受信していないと判断された場合(S524:NO)、制御部10は処理をステップS524へ戻し、受信したと判断されるまで待機する。受信したと判断された場合(S524:YES)、制御部10は、パケットID対応情報のレコードを送信者のpubrelメッセージの送信者の識別情報([source_user(broker)_id])及びpubrelメッセージのパケットID([source_pid])で検索し、検索されたレコードを削除し(ステップS525)、1つのpublish メッセージの配信処理を終了する。   When it is determined in step S522 that the pubrec message has been received from all the other server devices 1 (S522: YES), the control unit 10 pubrecs to the transmission source (publisher or other server device 1) of the received publish message. A message is returned (step S523). Subsequently, the control unit 10 determines whether or not the pubrel message has been received from the sender of the publish message (step S524). If it is determined that it has not been received (S524: NO), the control unit 10 returns the process to step S524, and waits until it is determined that it has been received. If it is determined that it has been received (S524: YES), the control unit 10 records the packet ID correspondence information in the sender's pubrel message sender identification information ([source_user (broker) _id]) and the pubrel message packet. The search is performed using the ID ([source_pid]), the searched record is deleted (step S525), and the distribution process for one publish message is terminated.

図40から図42を参照して、図39のフローチャートに示した処理手順を具体的に説明する。図40から図42は、パケットID対応情報の内容例を示す図である。まず図40は、パブリッシャであるクライアント装置2(p1)がpublish メッセージを送信してから、2つのブローカであるサーバ装置1(b1, b2)を経由してサブスクライバであるクライアント装置2(s1)へpublish メッセージが送信される時点までのパケットID対応情報(「pidmap」)を示す。図40に示すように、サーバ装置1(b1)は、パブリッシャであるクライアント装置2(p1)からタイミング(10)でpublish メッセージを受信すると(S501:YES)、クライアント装置2(s2)とのセッションにおいてパケットID「0x126 」を採番する(S516)。サーバ装置1(b1)は、パケットID対応情報(pid_map_u2u )に識別情報「p1」の送信者からのパケットID「0x112 」と識別情報「s2」の受信者へのパケットID「0x126 」の対応関係を示すレコード(source_user_id=p1, target_user_id=s2, s_pid=0x112, t_pid=0x126, sent=false)を作成して記憶する(S517)。制御部10は、採番したパケットID「0x126 」を用いて(20)のタイミングで識別情報「s2」の受信者へpublish メッセージを送信する(S518)。(30)のタイミングで識別情報「s2」の受信者からは、pubrecメッセージが送信されるので、サーバ装置1(b1)はこれを受信し(S520)、送信完了の論理値(sentの初期値は「false 」)を「true」で更新する(S522)。   The processing procedure shown in the flowchart of FIG. 39 will be specifically described with reference to FIGS. 40 to 42 are diagrams showing examples of contents of the packet ID correspondence information. First, in FIG. 40, after the client device 2 (p1) as a publisher transmits a publish message, the client device 2 (s1) as a subscriber passes through the server devices 1 (b1, b2) as two brokers. Indicates packet ID correspondence information (“pidmap”) up to the time when a publish message is transmitted. As shown in FIG. 40, when the server apparatus 1 (b1) receives a publish message at timing (10) from the client apparatus 2 (p1) which is the publisher (S501: YES), a session with the client apparatus 2 (s2) is performed. Then, the packet ID “0x126” is numbered (S516). The server apparatus 1 (b1) associates the packet ID correspondence information (pid_map_u2u) with the packet ID “0x112” from the sender of the identification information “p1” and the packet ID “0x126” to the receiver of the identification information “s2”. (Source_user_id = p1, target_user_id = s2, s_pid = 0x112, t_pid = 0x126, sent = false) are created and stored (S517). The control unit 10 transmits a publish message to the recipient of the identification information “s2” at the timing (20) using the numbered packet ID “0x126” (S518). Since the pubrec message is transmitted from the recipient of the identification information “s2” at the timing of (30), the server apparatus 1 (b1) receives this (S520), and the transmission complete logical value (initial value of sent) ("False") is updated with "true" (S522).

サーバ装置1(b1)は、他のサーバ装置1(b2)へもpublish メッセージを送信すべくサーバ装置1(b2)とのセッションにおいてパケットID「0x125 」を採番する(S516、S506)。サーバ装置1(b1)は、パケットID対応情報(pid_map_u2b )に識別情報「p1」の送信者からのパケットID「0x112 」と識別情報「b2」の受信者へのパケットID「0x125 」の対応関係のレコード(source_user_id=p1, target_broker_id=b2, s_pid=0x112, t_pid=0x125, sent=false)を記憶する(S517)。制御部10は、採番したパケットID「0x125 」を用いて(20)のタイミングでサーバ装置1(b2)へpublish メッセージを送信する(S518)。図40に示すタイミングでは、識別情報「b2」の受信者からのpubrecメッセージは未受信であるから、対応するレコードにおける送信完了の論理値(sent)は初期値「false 」のままである。   The server apparatus 1 (b1) assigns a packet ID “0x125” in a session with the server apparatus 1 (b2) to transmit a publish message to the other server apparatus 1 (b2) (S516 and S506). The server apparatus 1 (b1) associates the packet ID correspondence information (pid_map_u2b) with the packet ID “0x112” from the sender of the identification information “p1” and the packet ID “0x125” to the receiver of the identification information “b2”. (Source_user_id = p1, target_broker_id = b2, s_pid = 0x112, t_pid = 0x125, sent = false) are stored (S517). The control unit 10 transmits a publish message to the server apparatus 1 (b2) at the timing (20) using the numbered packet ID “0x125” (S518). At the timing shown in FIG. 40, since the pubrec message from the recipient of the identification information “b2” has not been received, the transmission completion logical value (sent) in the corresponding record remains the initial value “false”.

図40に示す例では、サーバ装置1(b2)においてもサブスクライバであるクライアント装置2(s1)へpublish メッセージを送信するに際し、パケットID「0x134 」を採番する(S506)。制御部10は、パケットID対応情報(pid_map_b2u )に識別情報「b1」の送信者からのパケットID「0x125 」と、識別情報「s1」の受信者へのパケットID「0x134 」との対応関係を示すレコード(source_broker_id=b1, target_user_id=s1, x_pid=0x125, t_pid=0x134, sent=false)を作成して記憶する(S507)。サーバ装置1(b2)の制御部10は、採番したパケットID「Z 」を用いて(30)のタイミングでクライアント装置2(s1)へpublish メッセージを送信する(S508)。   In the example shown in FIG. 40, when the publish message is transmitted to the client apparatus 2 (s1), which is also a subscriber, in the server apparatus 1 (b2), the packet ID “0x134” is numbered (S506). The control unit 10 sets the correspondence between the packet ID “0x125” from the sender of the identification information “b1” and the packet ID “0x134” to the receiver of the identification information “s1” in the packet ID correspondence information (pid_map_b2u). A record shown (source_broker_id = b1, target_user_id = s1, x_pid = 0x125, t_pid = 0x134, sent = false) is created and stored (S507). The control unit 10 of the server apparatus 1 (b2) transmits a publish message to the client apparatus 2 (s1) at the timing (30) using the numbered packet ID “Z” (S508).

図41は、図40の後、サーバ装置1(b2)からpubrecメッセージが送信される時点(タイミング(40))までのパケットID対応情報(「pidmap」)を示す。図41では、サーバ装置1(b2)は、(30)のタイミングでクライアント装置2(s1)へpublish メッセージを送信すると、順序性を守ってサーバ装置1(b1)へpubrecメッセージを送信する(S510)。これにより、サーバ装置1(b1)は、自身が送信したpublish メッセージについて、受信者であるサーバ装置1(b2)からpubrecメッセージを受信するので(S520)、対応するパケットID対応情報(pid_map_u2b )のレコードの送信完了の論理値(sent)を「true」に更新している(S521)。サーバ装置1(b1)は、他のサーバ装置1全てからpubrecメッセージを受信するので(S522:YES)、この後、パブリッシャであるクライアント装置2(p1)へ向けて、pubrecメッセージを送信する。   FIG. 41 shows packet ID correspondence information (“pidmap”) up to the point (timing (40)) when the pubrec message is transmitted from the server apparatus 1 (b2) after FIG. In FIG. 41, when the server apparatus 1 (b2) transmits a publish message to the client apparatus 2 (s1) at the timing (30), the server apparatus 1 (b2) transmits a pubrec message to the server apparatus 1 (b1) in order (S510). ). As a result, the server apparatus 1 (b1) receives the pubrec message from the server apparatus 1 (b2), which is the recipient, for the publish message transmitted by itself (S520), and therefore the corresponding packet ID correspondence information (pid_map_u2b) The logical value (sent) of the record transmission completion is updated to “true” (S521). The server device 1 (b1) receives the pubrec message from all the other server devices 1 (S522: YES), and thereafter transmits the pubrec message to the client device 2 (p1) that is the publisher.

図41の例では、サーバ装置1(b2)においても、受信者であるクライアント装置2(s1)からpubrecメッセージを受信したので、対応するパケットID対応情報(pid_map_b2u )のレコードの送信完了の論理値(sent)を「true」に更新している(S512)。   In the example of FIG. 41, since the server apparatus 1 (b2) also receives the pubrec message from the client apparatus 2 (s1) as the receiver, the logical value of the transmission completion of the record of the corresponding packet ID correspondence information (pid_map_b2u) (Sent) is updated to “true” (S512).

図42は、パブリッシャであるクライアント装置2(p1)からのpublish メッセージの配信処理が完了した後のパケットID対応情報(「pidmap」)を示す。サーバ装置1(b1)は、(40)のタイミングで受信したpubrecメッセージにより、他のサーバ装置1全てからpubrecメッセージを受信したと判断するので(S522:YES)、(50)のタイミングで、パブリッシャであるクライアント装置2(p1)へ向けて、pubrecメッセージを送信する(S523)。   FIG. 42 shows the packet ID correspondence information (“pidmap”) after the publish message distribution process from the client device 2 (p1), which is the publisher, is completed. Since the server apparatus 1 (b1) determines that the pubrec message has been received from all the other server apparatuses 1 based on the pubrec message received at the timing (40) (S522: YES), the publisher at the timing (50). The pubrec message is transmitted to the client apparatus 2 (p1) that is (S523).

パブリッシャであるクライアント装置2(p1)は、パケットID「0x112 」について受信者であるサーバ装置1(b1)からpubrecメッセージを受信するので、pubrelメッセージを送信する。サーバ装置1(b1)は、pubrelメッセージを受信したので(S524:YES)、送信者の識別情報「p1」及びpubrelメッセージのパケットID「0x112 」でパケットID対応情報を検索し、「pid_map_u2u 」及び「pid_map_u2b 」にて合致する2つレコードをいずれも削除し(S525)、配信処理を終了する。   The client device 2 (p1) that is the publisher receives the pubrec message from the server device 1 (b1) that is the receiver for the packet ID “0x112”, and therefore transmits the pubrel message. Since the server apparatus 1 (b1) has received the pubrel message (S524: YES), the server apparatus 1 (b1) searches the packet ID correspondence information with the identification information “p1” of the sender and the packet ID “0x112” of the pubrel message, and “pid_map_u2u” and Both the two records that match in “pid_map_u2b” are deleted (S525), and the distribution process is terminated.

サーバ装置1(b1)はネットワークコントローラの動作により、サーバ装置1(b2)を受信者とするパケットID「0x125 」のメッセージについて、pubrecメッセージを受信すると、pubrelメッセージを送信する。これによりサーバ装置1(b2)でも、pubrelメッセージを受信したので(S513:YES)、送信者の識別情報「b1」及びpubrelメッセージのパケットID「0x125 」でパケットID対応情報を検索し、「pid_map_b2u 」にて合致する2つレコードをいずれも削除し(S514)、配信処理を終了する。   When the server apparatus 1 (b1) receives the pubrec message for the message of the packet ID “0x125” having the server apparatus 1 (b2) as the receiver by the operation of the network controller, the server apparatus 1 (b1) transmits the pubrel message. As a result, the server apparatus 1 (b2) also receives the pubrel message (S513: YES), and searches for the packet ID correspondence information using the sender identification information “b1” and the packet ID “0x125” of the pubrel message, and “pid_map_b2u ”Are deleted (S514), and the distribution process is terminated.

上述の処理に示したように、QoS =2に調停された場合もQoS =1に調停された場合と同様に、各サーバ装置1における処理の順序性は保たれ、それに加えてパケットID対応情報を各自記憶される。QoS =2の場合、セッションが切断されたことで再接続時に同一のパケットIDを使用してpublish メッセージが再送されるが、各サーバ装置1は、同一の送信者から同一のパケットIDを使用したpublish メッセージについて、受信者からpubrecメッセージを受信しているケースでは再送を行なわない。これにより、パブリッシャからサブスクライバまでのメッセージが、異なるセッションを跨ぐケースでも、メッセージの到達をQoS =2で保証することが可能である。   As shown in the above-described processing, the order of processing in each server device 1 is maintained even when QoS = 2 is adjusted, as in the case of QoS = 1. In addition, packet ID correspondence information Each is memorized. When QoS = 2, the publish message is retransmitted using the same packet ID at the time of reconnection because the session is disconnected, but each server device 1 uses the same packet ID from the same sender. The publish message is not retransmitted if a pubrec message is received from the recipient. As a result, even when the message from the publisher to the subscriber crosses different sessions, the arrival of the message can be guaranteed with QoS = 2.

(4.2)切断発生時
ブローカがダウンした場合は保証しないという前提で、パブリッシャであるクライアント装置2とサーバ装置1との間、2つのサーバ装置1の間、サーバ装置1とサブスクライバであるクライアント装置2との間のセッションがメッセージのやり取り途中で切断した場合について説明する。なお以下の説明は、図38に示した構成におけるセッションJからセッションMの内のいずれか1つ又は複数が切断された例を挙げて説明する。
(4.2) When a disconnection occurs On the premise that no guarantee is made if the broker goes down, between the client device 2 that is the publisher and the server device 1, between the two server devices 1, and between the server device 1 and the client that is the subscriber A case where the session with the device 2 is disconnected in the middle of message exchange will be described. In the following description, an example in which any one or a plurality of sessions J to M in the configuration illustrated in FIG. 38 is disconnected will be described.

(4.2.1)パブリッシャ・ブローカ間
パブリッシャであるクライアント装置2から、QoS =2で調停されたサブスクライバへのデータの送信に関し、パブリッシャとブローカとの間のセッションが切断されるケースについて考える。このケースは、図40に示したパブリッシャであるクライアント装置2(p1)からpublish メッセージが送信された後、サーバ装置1(b1)からpubrecメッセージが送信される前に、クライアント装置2(p1)とサーバ装置1(b1)の間のセッションJが切断されるケースである。
(4.2.1) Between Publisher and Broker Consider a case in which a session between a publisher and a broker is disconnected with respect to transmission of data from the publisher client device 2 to a subscriber arbitrated with QoS = 2. In this case, after the publish message is transmitted from the client device 2 (p1) which is the publisher shown in FIG. 40, before the pubrec message is transmitted from the server device 1 (b1), the client device 2 (p1) In this case, the session J between the server apparatuses 1 (b1) is disconnected.

このケースでは、パブリッシャであるクライアント装置2(p1)は、送信したpublish メッセージに対するpubrecメッセージが返されるまで、そのpublish メッセージを送信バッファに一時記憶したままとする(図3)。セッションJが再度確立された場合、クライアント装置2(p1)は、送信バッファに一時記憶しているpublish メッセージを再度セッションJにおいて、同一パケットIDを用いて接続先のサーバ装置1(b1)へ送信する。サブスクライバへのメッセージの到達保証がQoS =2に調停されている場合、この2回目以降の同一のpublish メッセージを起源とするpublish メッセージが、サブスクライバであるクライアント装置2で重複して受信処理されることを回避しなければならない。   In this case, the client device 2 (p1), which is the publisher, temporarily stores the publish message in the transmission buffer until a pubrec message for the transmitted publish message is returned (FIG. 3). When the session J is established again, the client apparatus 2 (p1) transmits the publish message temporarily stored in the transmission buffer to the connection destination server apparatus 1 (b1) using the same packet ID again in the session J. To do. When the message arrival guarantee to the subscriber is arbitrated to QoS = 2, the publish message originating from the same publish message after the second time is received and processed repeatedly by the client device 2 as the subscriber. Must be avoided.

本実施の形態におけるサーバ装置1の処理により、図40の状態でセッションJが切断されるケースでも、まず、サブスクライバであるクライアント装置2へ(s1)のメッセージ到達を「Exactly once」(正確に1回、ちょうど1回だけ届く)(QoS =2)とすることができる。サーバ装置1(b1)は、切断される前にパブリッシャであるクライアント装置2(p1)から受信したpublish メッセージについて、クライアント装置2(s1)が通信接続している他のサーバ装置1(b2)へのpublish メッセージの送信を完了している場合、パケットID対応情報のレコード(pid_map_u2b)を一時記憶している。したがって、再送されたpublish メッセージをパブリッシャから受信した場合、サーバ装置1(b1)は、同一の送信者からの同一のパケットIDを含み、他のサーバ装置1(b2)を受信者とするレコードを検索できる(source_user_id=p1, source_pid=0x112, target_broker_id=b2)。   Even in the case where the session J is disconnected in the state of FIG. 40 by the processing of the server device 1 in the present embodiment, first, the message arrival of (s1) to the client device 2 as the subscriber is “Exactly once” (exactly 1 (QoS = 2). The server apparatus 1 (b1) sends the publish message received from the client apparatus 2 (p1), which is the publisher before being disconnected, to the other server apparatus 1 (b2) to which the client apparatus 2 (s1) is connected. When the transmission of the publish message is completed, a packet ID correspondence information record (pid_map_u2b) is temporarily stored. Therefore, when the retransmitted publish message is received from the publisher, the server device 1 (b1) includes a record including the same packet ID from the same sender and the other server device 1 (b2) as the receiver. Searchable (source_user_id = p1, source_pid = 0x112, target_broker_id = b2).

レコードが検索できた場合、送信先のサーバ装置1(b2)から、サーバ装置1(b1)へpubrecメッセージが送信される前、即ち、その先に通信接続しているクライアント装置2(s1)へのpublish メッセージの送信前であれば、検索されたレコードにおける送信完了の論理値(sent)は「false 」である。この場合、サーバ装置1(b1)は、検索されたレコードに含まれる受信者(target_broker_id=b2 )へのパケットID(target_pid=0x125)を用いてpublish メッセージを再送する。サーバ装置1(b1)からのpublish メッセージの再送を受けたサーバ装置1(b2)は、通信接続しているクライアント装置2(s1)からのpubrecメッセージを受信していない場合、publish メッセージを同様にして再送する。セッションKにおけるMQTTモデルによって、クライアント装置2(s1)は、pubrelメッセージを受信するまでは、再送されたpublish メッセージを受信しても受信処理せずに破棄するから、重複して受信処理を行なうことはない。   When the record can be retrieved, before the pubrec message is transmitted from the destination server apparatus 1 (b2) to the server apparatus 1 (b1), that is, to the client apparatus 2 (s1) connected to the destination. If it is before transmission of the publish message, the logical value (sent) of transmission completion in the retrieved record is “false”. In this case, the server apparatus 1 (b1) retransmits the publish message using the packet ID (target_pid = 0x125) to the recipient (target_broker_id = b2) included in the retrieved record. When the server apparatus 1 (b2) that has received the retransmission of the publish message from the server apparatus 1 (b1) has not received the pubrec message from the client apparatus 2 (s1) that is connected for communication, the publish message is similarly set. And resend. According to the MQTT model in session K, the client apparatus 2 (s1) discards the retransmitted publish message without receiving it until it receives the pubrel message. There is no.

サーバ装置1(b2)は、通信接続しているクライアント装置2(s1)へ、セッションJの切断前にパブリッシャから送信されたメッセージに基づくpublish メッセージを送信済みである場合、pubrecメッセージをサーバ装置1(b1)へ返しているか、返そうとしている。サーバ装置1(b1)はほどなく、このpubrecメッセージを受信し、検索されたレコードにおける送信完了の論理値(sent)は「true」に更新されている。パブリッシャからpublish メッセージの再送を受けた時点で、検索されたレコードの送信完了の論理値(sent)が「true」である場合、サーバ装置1(b1)はサーバ装置1(b2)へ向けてpublish メッセージを再送しない。このように、クライアント装置2(s1)へ、セッションJの切断前にパブリッシャから送信されたpublish メッセージに基づくpublish メッセージが送信済みである場合、サーバ装置1(b2)へも同一のpublish メッセージに基づくpublish メッセージの再送はなされない。クライアント装置2(s1)へ重複してメッセージが到達することはない。   If the server apparatus 1 (b2) has already transmitted a publish message based on the message transmitted from the publisher before the session J is disconnected to the client apparatus 2 (s1) connected for communication, the server apparatus 1 transmits the pubrec message. Returning to (b1) or trying to return. The server apparatus 1 (b1) will soon receive this pubrec message, and the logical value (sent) of transmission completion in the retrieved record is updated to “true”. When the logical value (sent) of transmission completion of the retrieved record is “true” when the publish message is retransmitted from the publisher, the server device 1 (b1) publishes to the server device 1 (b2). Do not resend the message. As described above, when the publish message based on the publish message transmitted from the publisher before the session J is disconnected has been transmitted to the client apparatus 2 (s1), the server apparatus 1 (b2) is also based on the same publish message. The publish message is not resent. No duplicate messages arrive at the client device 2 (s1).

パブリッシャからpublish メッセージの再送を受けた時点で、検索されたレコードの送信完了の論理値(sent)が「false 」である場合、サーバ装置1(b1)はサーバ装置1(b2)へ向けてpublish メッセージを再送するが、サーバ装置1(b2)では、同一パケットIDによるpublish メッセージを受信済みで処理しているので、この再送されたpublish メッセージはMQTTモデルに基づくセッション毎の到達保証により、破棄される。クライアント装置2(s1)へ重複してメッセージが到達することはない。   When the logical value (sent) of transmission completion of the retrieved record is “false” when the publish message is retransmitted from the publisher, the server device 1 (b1) publishes toward the server device 1 (b2). Although the message is resent, the server apparatus 1 (b2) has already received and processed the publish message with the same packet ID. Therefore, the resent publish message is discarded by the arrival guarantee for each session based on the MQTT model. The No duplicate messages arrive at the client device 2 (s1).

サーバ装置1(b1)は、切断される前にパブリッシャであるクライアント装置2(p1)から受信したpublish メッセージについて、識別情報「s1」のクライアント装置2が通信接続している他のサーバ装置1(b2)へのpublish メッセージの送信を行なう際に、他のサーバ装置1(b2)とのセッションLが切断されている場合、メッセージ及びその配信先をデータベース3(「store 」及び「store_target_broker」テーブル)として記憶する(後述)。このときサーバ装置1(b1)は、受信者を送信先であるはずであった他のサーバ装置1の識別情報「b2」、受信者へのパケットIDを「NULL」とし、送信完了の論理値を「true」とするパケットID対応情報(pid_map_u2b )のレコードを作成して記憶しておく。この場合、他のサーバ装置1(b2)側で、データベース3(「store 」及び「store_target_broker」テーブル)に記憶されている自身宛のメッセージが保存されていることを認識でき、受信処理がなされるはずである。セッションJが切断された後、パブリッシャからメッセージの再送を受けたとしても、同一の送信者からの同一のパケットIDを含み、他のサーバ装置1(b2)を受信者とするレコードを検索でき、しかも送信完了が「true」であるから、セッションLが再接続されたとしても再送を行なわれることが回避される。これにより、メッセージが重複して到達することはない。   The server apparatus 1 (b1) is connected to another server apparatus 1 (to which the client apparatus 2 having the identification information “s1” is communicatively connected to the publish message received from the client apparatus 2 (p1) which is the publisher before being disconnected. When sending a publish message to b2), if the session L with the other server apparatus 1 (b2) is disconnected, the message and its delivery destination are stored in the database 3 ("store" and "store_target_broker" tables). Is stored as described later. At this time, the server apparatus 1 (b1) sets the identification information “b2” of the other server apparatus 1 that should have been the recipient and the packet ID to the receiver as “NULL”, and the logical value of the transmission completion A record of packet ID correspondence information (pid_map_u2b) with “true” is created and stored. In this case, the other server device 1 (b2) can recognize that the message addressed to itself stored in the database 3 (“store” and “store_target_broker” table) is stored, and the reception process is performed. It should be. Even if the message is retransmitted from the publisher after the session J is disconnected, a record including the same packet ID from the same sender and having the other server device 1 (b2) as the receiver can be searched. Moreover, since the transmission completion is “true”, it is avoided that retransmission is performed even if the session L is reconnected. This prevents duplicate messages from reaching.

図40の状態でセッションJが切断された場合に、サーバ装置1(b1)に直接的に通信接続しているサブスクライバであるクライアント装置2(s2)へのメッセージ到達についても「Exactly once」(QoS =2)とすることができる。   When the session J is disconnected in the state of FIG. 40, the message arrival to the client device 2 (s2), which is a subscriber directly connected to the server device 1 (b1), is also “Exactly once” (QoS = 2).

サーバ装置1(b1)は、切断される前にパブリッシャであるクライアント装置2(p1)から受信したpublish メッセージについて、クライアント装置2(s2)へのpublish メッセージの送信を完了している場合、パケットID対応情報のレコード(pid_map_u2u )を一時記憶している。したがって、再送されたpublish メッセージをパブリッシャから受信した場合、サーバ装置1(b1)は、同一の送信者からの同一のパケットIDを含み、クライアント装置2(s2)を受信者とするレコードを検索できる(source_user_id=p1, source_pid=0x112, target_user_id=s2)。   If the server apparatus 1 (b1) has completed transmission of the publish message to the client apparatus 2 (s2) for the publish message received from the client apparatus 2 (p1) that is the publisher before being disconnected, the packet ID Corresponding information record (pid_map_u2u) is temporarily stored. Therefore, when the retransmitted publish message is received from the publisher, the server apparatus 1 (b1) can search for a record including the same packet ID from the same sender and having the client apparatus 2 (s2) as the receiver. (Source_user_id = p1, source_pid = 0x112, target_user_id = s2).

レコードが検索できた場合、送信先のクライアント装置2(s2)から、サーバ装置1(b1)へpubrecメッセージが送信される前であれば、検索されたレコードにおける送信完了の論理値(sent)は「false 」である。この場合、サーバ装置1(b1)は、検索されたレコードに含まれる受信者へのパケットID(target_pid=0x126)を用いてpublish メッセージを再送する。サーバ装置1(b1)からのpublish メッセージの再送を受けたクライアント装置2(s2)は、pubrelメッセージを受信するまでは、再送されたpublish メッセージを受信しても受信処理せずに破棄するから、重複して受信処理を行なうことはない。   If the record can be retrieved, before the pubrec message is transmitted from the destination client device 2 (s2) to the server device 1 (b1), the logical value (sent) of the transmission completion in the retrieved record is "False". In this case, the server apparatus 1 (b1) retransmits the publish message using the packet ID (target_pid = 0x126) for the recipient included in the retrieved record. Since the client apparatus 2 (s2) that has received the retransmission of the publish message from the server apparatus 1 (b1) receives the retransmitted publish message and discards it without receiving it until the pubrel message is received. Duplicate reception processing is not performed.

レコードが検索でき、送信先のクライアント装置2(s2)から、サーバ装置1(b1)へpubrecメッセージが送信された後であれば、検索されたレコードにおける送信完了の論理値(sent)は「true」である。サーバ装置1(b1)は、再送されたpublish メッセージに基づくpublish メッセージの再送を行なわない。クライアント装置2(s2)へ重複してメッセージが到達することはない。   If the record can be retrieved and the pubrec message is transmitted from the destination client device 2 (s2) to the server device 1 (b1), the transmission completion logical value (sent) in the retrieved record is “true” Is. The server apparatus 1 (b1) does not retransmit the publish message based on the retransmitted publish message. No duplicate messages arrive at the client device 2 (s2).

サーバ装置1(b1)は、切断される前にパブリッシャであるクライアント装置2(p1)から受信したpublish メッセージについて、クライアント装置2(s2)へのpublish メッセージの送信を行なう際に、当該クライアント装置2(s2)とのセッションMが切断されているケースが考えられる。このケースは、ブローカ・サブスクライバ間の切断であるから後述にて説明する。   When the server apparatus 1 (b1) transmits a publish message to the client apparatus 2 (s2) for the publish message received from the client apparatus 2 (p1) that is the publisher before being disconnected, the client apparatus 2 A case where the session M with (s2) is disconnected can be considered. Since this case is a disconnection between broker and subscriber, it will be described later.

切断のタイミングが図40に示した状態以外である場合、サーバ装置1(b1)は、各セッションにおけるMQTTモデルにおけるネットワークコントローラの送信バッファに残存しているメッセージの有無に基づく処理(図15から図17)により、中断されたやり取りが再開され、メッセージのやり取りが完了する。図41、図42に示したように、pubrecメッセージがパブリッシャへ到達した後は、各セッションにおけるpubrelメッセージ及びpubcomp メッセージのやり取りが実行される。   When the disconnection timing is other than the state shown in FIG. 40, the server apparatus 1 (b1) performs processing based on the presence or absence of a message remaining in the transmission buffer of the network controller in the MQTT model in each session (FIG. 15 to FIG. 17), the interrupted exchange is resumed and the message exchange is completed. As shown in FIGS. 41 and 42, after the pubrec message reaches the publisher, the exchange of the pubrel message and the pubcomp message in each session is executed.

このように、セッション毎におけるQoS =2のみならず、セッションJ、セッションL及びセッションK、並びにセッションJ及びセッションMを跨ぐメッセージの到達保証を、セッションJが切断された場合でもQoS =2で達成することができる。   In this way, not only QoS = 2 for each session but also message arrival guarantees across session J, session L and session K, and session J and session M are achieved with QoS = 2 even when session J is disconnected. can do.

(4.2.2)ブローカ・サブスクライバ間
図40に示した状態で、サブスクライバであるクライアント装置2(s1)と、ブローカであるサーバ装置1(b2)との間で確立されていたセッションKが切断された場合のQoS =2の到達保証について説明する。図43は、サーバ装置1(b2)におけるサブスクライバとのセッション切断検知時の処理手順の一例を示すフローチャートである。
(4.2.2) Between Broker and Subscriber In the state shown in FIG. 40, there is a session K established between the client device 2 (s1) as a subscriber and the server device 1 (b2) as a broker. The arrival guarantee of QoS = 2 when disconnected is described. FIG. 43 is a flowchart illustrating an example of a processing procedure when detecting disconnection of a session with a subscriber in the server apparatus 1 (b2).

サーバ装置1(b2)の制御部10は、自身に通信接続していたサブスクライバであるクライアント装置2との切断を検知すると(ステップS601)、図15Aのフローチャートに示したMQTTの中途メッセージ情報の処理手順にしたがって、切断されたセッションの接続先のクライアント装置2向けのpublish メッセージが送信バッファに残存しているか否かを判断する(ステップS602)。残存していると判断された場合(S602:YES)、制御部10は、このpublish メッセージを中途メッセージ情報(パケットイメージと送信先のクライアント装置2の識別情報)としてデータベース3(「keep_mqtt 」テーブル)に記憶する(ステップS603)。送信バッファに残存していたpublish メッセージは消去される。   When the control unit 10 of the server apparatus 1 (b2) detects disconnection with the client apparatus 2 that is a subscriber connected to itself (step S601), the MQTT halfway message information processing illustrated in the flowchart of FIG. 15A is performed. According to the procedure, it is determined whether or not the publish message for the client apparatus 2 to which the disconnected session is connected remains in the transmission buffer (step S602). If it is determined that it remains (S602: YES), the control unit 10 uses the publish message as halfway message information (packet image and identification information of the destination client device 2) in the database 3 ("keep_mqtt" table). (Step S603). The publish message remaining in the send buffer is deleted.

制御部10は、一時記憶しているパケットID対応情報(pid_map_b2u 又はpid_map_u2u )の内、切断されたセッションの接続先のクライアント装置2を受信者とするレコードをデータベース3に自身の識別情報(broker_id)を対応付けて記憶する(ステップS604)。制御部10は、記憶したレコードを、一時記憶から削除する(ステップS605)。   The control unit 10 stores in the database 3 a record in which the client device 2 to which the disconnected session is connected is stored in the database 3 among the temporarily stored packet ID correspondence information (pid_map_b2u or pid_map_u2u). Are stored in association with each other (step S604). The control unit 10 deletes the stored record from the temporary storage (step S605).

制御部10は、切断されたセッションの接続先のクライアント装置2が再度自身へ通信接続のリクエストを送信してきたか否かを判断する(ステップS606)。送信してきたと判断された場合(S606:YES)、制御部10は、図4のフローチャートに示した処理手順(S1−S3:NO、S16)を実行する。制御部10は、自身が記憶し、接続先のクライアント装置2を受信者とするパケットID対応情報のレコードをデータベース3(pid_map_b2u )から参照する(ステップS607)。制御部10は、ステップS16の状態情報の復元の一環として、読み出したレコード(pid_map_b2u 又はpid_map_u2u )を一時記憶部13による一時記憶に戻す(ステップS608)。   The control unit 10 determines whether or not the client device 2 that is the connection destination of the disconnected session has transmitted a communication connection request to itself again (step S606). When it is determined that it has been transmitted (S606: YES), the control unit 10 executes the processing procedure (S1-S3: NO, S16) shown in the flowchart of FIG. The control unit 10 refers to a record of packet ID correspondence information stored in itself and having the connection destination client device 2 as a receiver from the database 3 (pid_map_b2u) (step S607). The control unit 10 returns the read record (pid_map_b2u or pid_map_u2u) to the temporary storage by the temporary storage unit 13 as part of the restoration of the state information in step S16 (step S608).

続いて制御部10は、図15Bのフローチャートに示した処理手順にしたがい、接続先のクライアント装置2へのpublish メッセージの送信は完了しているか否かを判断する(ステップS609)。送信が完了していないと判断された場合(S609:NO)、制御部10は、データベース3から、接続先のクライアント装置2へ送信されるべきであったメッセージ情報(中途メッセージ情報(「keep_mqtt」テーブル))をデータベース3から読み出す(ステップS610)。制御部10は、読み出したパケットIDをそのまま含むパケットイメージでpublish メッセージを送信する(ステップS611)。そして制御部10は、パケットID対応情報を参照し、再送したpublish メッセージに対応するpubrecメッセージをパブリッシャ側のサーバ装置1(b1)へ送信し(ステップS612)、切断検知時の処理を終了し、以後のMQTTモデルに基づくメッセージのやり取りを続行する。図4のフローチャートに示したステップS18の処理が終了し、サーバ装置1(b2)は配信処理を続行する(S9)。   Subsequently, the control unit 10 determines whether or not the transmission of the publish message to the connection destination client device 2 is completed according to the processing procedure shown in the flowchart of FIG. 15B (step S609). If it is determined that the transmission has not been completed (S609: NO), the control unit 10 sends message information (intermediate message information (“keep_mqtt”) that should have been transmitted from the database 3 to the client device 2 to be connected. Table)) is read from the database 3 (step S610). The control unit 10 transmits a publish message with a packet image including the read packet ID as it is (step S611). Then, the control unit 10 refers to the packet ID correspondence information, transmits a pubrec message corresponding to the retransmitted publish message to the server device 1 (b1) on the publisher side (step S612), and ends the process at the time of detecting disconnection. Continue to exchange messages based on the MQTT model. The process of step S18 shown in the flowchart of FIG. 4 ends, and the server apparatus 1 (b2) continues the distribution process (S9).

ステップS609にて、送信は完了していると判断された場合(SS609:YES)、制御部10は切断検知時の処理をそのまま終了する。またステップS606にて、送信されていないと判断された場合(S606:NO)、制御部10は、切断検知時の処理をそのまま終了する。この場合制御部10は、図4のフローチャートのS9へ処理を進めて配信処理を続行する。なおステップS606において送信されないと判断された場合、データベース3に記憶される各クライアント装置2の接続情報(「connections 」)を確認して自身ではないと判断してもよい。   If it is determined in step S609 that the transmission has been completed (SS609: YES), the control unit 10 ends the process at the time of detecting the disconnection as it is. If it is determined in step S606 that no transmission has been made (S606: NO), the control unit 10 ends the process at the time of detection of disconnection. In this case, the control unit 10 advances the process to S9 in the flowchart of FIG. 4 and continues the distribution process. If it is determined in step S606 that the data is not transmitted, the connection information (“connections”) of each client device 2 stored in the database 3 may be checked to determine that it is not itself.

一方、切断された先のクライアント装置2(s1)が新たに通信接続をリクエストした先のサーバ装置1における処理について説明する。新たな接続先のサーバ装置1は、新たな通信接続のリクエストに対し、図4のフローチャートに示した処理手順を実行する。この場合、セッション情報がデータベース3(「keep_sub」テーブル)に記憶されているので、接続先のサーバ装置1は、ステップS16にて状態情報を復元する。   On the other hand, processing in the server apparatus 1 to which the disconnected client apparatus 2 (s1) newly requested communication connection will be described. The new connection destination server apparatus 1 executes the processing procedure shown in the flowchart of FIG. 4 in response to a new communication connection request. In this case, since the session information is stored in the database 3 (“keep_sub” table), the connection destination server apparatus 1 restores the state information in step S16.

サーバ装置1は、データベース3から接続先のクライアント装置2(s1)への送信に係るパケットID対応情報(pid_map_b2u )を検索し、検索された場合にはこれを読み出して状態情報の一部として復元する(S16)。新たな接続先であるサーバ装置1は、図15Bの処理手順にしたがって、データベース3の保存メッセージ及び配信先情報又は中途メッセージ情報(「store 」及び「store_target_broker_user」テーブル、又は「keep_mqtt」テーブル)を検索し、メッセージがあると判断された場合(S106:YES)、メッセージを読み出してクライアント装置2へ送信する(S107)。制御部10は、送信したメッセージをデータベース3から削除する(S108)。制御部10は、パケットID対応情報から、publish メッセージの送信元(他のサーバ装置1又はパブリッシャ)へ向けて、pubrec メッセージを送信し、pubrelメッセージ及びpubcomp メッセージのやり取りを完了させる。これによりデータベース3からの配信(S18)を終了する。   The server device 1 retrieves the packet ID correspondence information (pid_map_b2u) related to transmission from the database 3 to the connection destination client device 2 (s1), and when retrieved, retrieves it and restores it as part of the state information (S16). The server device 1 which is a new connection destination searches the stored message and the delivery destination information or midway message information (the “store” and “store_target_broker_user” table or “keep_mqtt” table) in the database 3 according to the processing procedure of FIG. If it is determined that there is a message (S106: YES), the message is read and transmitted to the client device 2 (S107). The control unit 10 deletes the transmitted message from the database 3 (S108). The control unit 10 transmits a pubrec message from the packet ID correspondence information to the transmission source of the publish message (other server device 1 or publisher), and completes the exchange of the pubrel message and the pubcomp message. Thereby, the distribution from the database 3 (S18) is terminated.

図43のフローチャートに示した処理手順を具体的に説明する。図40におけるセッションKが、サーバ装置1(b2)がクライアント装置2(s1)へ(30)のタイミングでpublish メッセージを送信する前に切断されるケースが考えられる。このケースでは、keep接続の処理(図9、図10から図14)により、切断されている間に配信されたメッセージは、保存メッセージ及び配信先情報(「store 」及び「store_target」テーブル)として記憶される(クライアント装置2(s2)がkeep接続している場合)。再接続後にサーバ装置1(b2)又は新たなサーバ装置1の処理によってデータベース3から配信される(クライアント装置2(s1)がkeep接続している場合)。再接続後のサーバ装置1では、切断されたクライアント装置2を対象とするパケットID対応情報を復元できるので、既にクライアント装置2がpublish メッセージを受信処理済みであるか否か(pubrecメッセージを送信しているか否か)を把握することができ、メッセージを重複して送信することなくQoS =2を達成できる。   The processing procedure shown in the flowchart of FIG. 43 will be specifically described. The session K in FIG. 40 may be disconnected before the server apparatus 1 (b2) transmits a publish message to the client apparatus 2 (s1) at the timing (30). In this case, the message distributed while being disconnected by the keep connection process (FIGS. 9, 10 to 14) is stored as a stored message and distribution destination information (“store” and “store_target” tables). (When the client apparatus 2 (s2) is kept connected). After reconnection, the data is distributed from the database 3 by processing of the server device 1 (b2) or a new server device 1 (when the client device 2 (s1) is kept connected). Since the server apparatus 1 after the reconnection can restore the packet ID correspondence information for the disconnected client apparatus 2, it is determined whether the client apparatus 2 has already received the publish message (the pubrec message is transmitted). And QoS = 2 can be achieved without sending duplicate messages.

セッションKが、サーバ装置1(b2)がクライアント装置2(s1)へ(30)のタイミングでpublish メッセージを送信した後、pubrecメッセージを受信する前に切断されるケースも考えられる。このケースでは、再接続後にサーバ装置1(b2)又は新たなサーバ装置1の処理によって、データベース3の中途メッセージ情報(「keep_mqtt 」テーブル)を参照した処理(図15から図19)により、中断されたやり取りが再開され、メッセージのやり取りが完了する。   There may be a case where the session K is disconnected before the pubrec message is received after the server device 1 (b2) transmits the publish message to the client device 2 (s1) at the timing (30). In this case, the server device 1 (b2) or the new server device 1 after the reconnection interrupts the processing by referring to the midway message information ("keep_mqtt" table) in the database 3 (FIGS. 15 to 19). Exchange is resumed and message exchange is completed.

また、図40に示した例で、パブリッシャであるクライアント装置2(p1)から受信したpublish メッセージについて、サーバ装置1(b1)がクライアント装置2(s2)へのpublish メッセージの送信を行なう際に、当該クライアント装置2とのセッションMが切断されているケースもブローカ・サブスクライバ間の切断である。セッションMが切断されるケースでは、切断中にクライアント装置2(s2)が受信すべきメッセージは、識別情報「s2」とする配信先情報と共にデータベース3(「store 」及び「store_target」テーブル)に記憶される(クライアント装置2(s2)がkeep接続している場合)。そしてこのときサーバ装置1(b1)は、受信者を送信先であるはずであったクライアント装置2の識別情報「s2」、受信者へのパケットIDを「NULL」とし、送信完了の論理値を「true」とするパケットID対応情報(pid_map_u2u )のレコードを作成して記憶している。   Further, in the example shown in FIG. 40, when the server apparatus 1 (b1) transmits a publish message to the client apparatus 2 (s2) for the publish message received from the client apparatus 2 (p1) as the publisher, The case where the session M with the client apparatus 2 is disconnected is also a disconnection between broker and subscriber. In the case where the session M is disconnected, the message to be received by the client device 2 (s2) during the disconnection is stored in the database 3 (“store” and “store_target” tables) together with the distribution destination information with the identification information “s2”. (When the client apparatus 2 (s2) is kept connected). At this time, the server apparatus 1 (b1) sets the identification information “s2” of the client apparatus 2 that should have been the receiver as the transmission destination, the packet ID to the receiver as “NULL”, and sets the logical value of transmission completion. A record of packet ID correspondence information (pid_map_u2u) to be “true” is created and stored.

このケースでは、セッションMが再接続された場合、keep接続の処理により(図4)、記憶されている保存メッセージ及び配信先情報に基づくデータベース3(「store 」及び「store_target」テーブル)からのクライアント装置2(s2)への配信処理が行なわれる。再接続先であるサーバ装置1(b1)では、パケットID対応情報を復元できる。セッションJが切断された後、パブリッシャからメッセージの再送を受けたとしても、同一の送信者、同一のパケットID、クライアント装置2(s2)を受信者とするレコードを検索でき、検索されたレコードの送信完了は「true」であるから、セッションMが再接続されたとしても再送が行なわない。このようにメッセージの重複到達が回避される。   In this case, when the session M is reconnected, the client from the database 3 (“store” and “store_target” table) based on the stored message and the delivery destination information stored by the keep connection process (FIG. 4). Distribution processing to the device 2 (s2) is performed. The server device 1 (b1) that is the reconnection destination can restore the packet ID correspondence information. Even if the message is retransmitted from the publisher after session J is disconnected, a record with the same sender, the same packet ID, and the client device 2 (s2) as a receiver can be searched. Since the transmission completion is “true”, even if the session M is reconnected, no retransmission is performed. In this way, duplicate arrival of messages is avoided.

このケースにおいてクライアント装置2(s2)が別のサーバ装置1に通信接続した場合も、データベース3(「store 」及び「store_target」テーブル)から配信される。この場合も、別のサーバ装置1にて復元されるパケットID対応情報(pid_map_u2u )によって、既に送信済みであることが認識されて重複した送信が回避される。   In this case, even when the client apparatus 2 (s2) is connected to another server apparatus 1 by communication, it is distributed from the database 3 ("store" and "store_target" tables). Also in this case, the packet ID correspondence information (pid_map_u2u) restored by another server device 1 recognizes that transmission has already been performed, and avoids duplicate transmission.

(4.2.3)ブローカ・ブローカ間
パブリッシャからサブスクライバへのメッセージを仲介する2つのブローカ間で確立されていたセッションが切断された場合の到達保証について説明する。ブローカ間のセッションは上述したようにkeep接続が選択されている。ブローカ間のセッションの切断(図40におけるセッションLの切断)については、keep接続に対する保存メッセージの記憶(「store 」)と、(2.2.3)で説明した切断されている他のサーバ装置1を経由して送信されるメッセージであったことを示すブローカ経由の配信先情報(「store_target_broker_user」テーブル)の記憶とをパケットID対応情報と共に用いて処理を行なう。
(4.2.3) Broker-Broker A description will be given of arrival guarantee when a session established between two brokers mediating a message from a publisher to a subscriber is disconnected. As described above, the keep connection is selected for the session between brokers. Regarding disconnection of a session between brokers (disconnection of session L in FIG. 40), storage of a save message for a keep connection (“store”) and other disconnected server devices described in (2.2.3) Processing is performed using the storage of distribution destination information (“store_target_broker_user” table) via the broker indicating that the message is transmitted via 1 together with the packet ID correspondence information.

QoS =2の場合、ブローカ間のセッションが切断された場合のサーバ装置1による処理は、QoS =1について図24のフローチャートに示した処理手順と基本的に同様である。ただしQoS =2の場合には、ステップS306で送信するpubackメッセージではなくpubrecメッセージであり、ステップS316で保存メッセージを削除するステップS315のトリガはpubackメッセージではなく、pubcomp メッセージを受信することである。そしてステップS305にて記憶される「本来であれば他のサーバ装置1とセッションを確立しているクライアント装置2へ送信されていたはずのメッセージ」とその配信先情報(「store 」及び「store_target_broker_user」テーブル)に、送信完了しているか否か(pubrecメッセージをその時点で受信しているか否か)の情報を共に記憶する。   In the case of QoS = 2, the processing by the server device 1 when the session between brokers is disconnected is basically the same as the processing procedure shown in the flowchart of FIG. 24 for QoS = 1. However, when QoS = 2, the pubrec message is sent instead of the puback message transmitted in step S306, and the trigger of step S315 for deleting the stored message in step S316 is receiving the pubcomp message instead of the puback message. In step S305, “the message that should have been originally transmitted to the client device 2 that has established a session with the other server device 1” and its distribution destination information (“store” and “store_target_broker_user”) are stored. Information on whether or not transmission is completed (whether or not a pubrec message is received at that time) is stored in the table.

ブローカ間が切断された場合の処理について、具体例を挙げて説明する。ブローカ間のセッションが切断された場合の処理について具体例を挙げて説明する。図44から図46は、ブローカ間のセッションが切断された場合の処理の例を示す説明図である。図44の例で示される装置の接続構成は、クライアント装置2(s2)を省略している点以外は図38にて示した例と同一である。   A process when the broker is disconnected will be described with a specific example. A process when a session between brokers is disconnected will be described with a specific example. 44 to 46 are explanatory diagrams illustrating an example of processing when a session between brokers is disconnected. The connection configuration of the device shown in the example of FIG. 44 is the same as the example shown in FIG. 38 except that the client device 2 (s2) is omitted.

図44は、ブローカであるサーバ装置1(b1, b2)間のセッションが切断された場合にサーバ装置1の一時記憶部13及びデータベース3に記憶される情報の内容例を示している。図44に示した例は、QoS =1の場合の図25を参照して説明した処理と、切断が検知されるまで同様である。図44のQoS =2の場合には、各サーバ装置1がパケットID対応情報を記憶している点で異なる。   FIG. 44 shows an example of contents of information stored in the temporary storage unit 13 and the database 3 of the server device 1 when the session between the server devices 1 (b1, b2) serving as brokers is disconnected. The example shown in FIG. 44 is the same as the processing described with reference to FIG. 25 in the case of QoS = 1 until disconnection is detected. 44 is different in that each server device 1 stores packet ID correspondence information.

図45は、図44に示した状態から、ブローカ間のセッションLが再確立された後の処理を示し、サーバ装置1(b2)と、サブスクライバであるクライアント装置2(s1)との間のセッションKが維持されている場合の処理を示している。図44で説明したように保存メッセージ及びブローカ経由の配信先情報がデータベース3(「store 」及び「store_target_broker_user」テーブル)に記憶されている。これにより、QoS =1の場合は、ブローカ間のセッションLが切断された場合には、サーバ装置1(b2)からクライアント装置2(s1)へのメッセージの送信がなされたかが不明であるため、サーバ装置1(b2)から念のためにメッセージを送信しておき、確実に送信することが達成できた。QoS =2の場合は、これらの情報とパケットID対応情報との併用により、1回の送信(Excactry once )とすることができる。   FIG. 45 shows the processing after the session L between brokers is re-established from the state shown in FIG. 44, and the session between the server device 1 (b2) and the client device 2 (s1) as a subscriber. The process when K is maintained is shown. As described with reference to FIG. 44, the stored message and the delivery destination information via the broker are stored in the database 3 (“store” and “store_target_broker_user” table). Thereby, in the case of QoS = 1, when the session L between the brokers is disconnected, it is unknown whether a message is transmitted from the server device 1 (b2) to the client device 2 (s1). A message was transmitted from the device 1 (b2) just in case, and it was possible to reliably transmit the message. In the case of QoS = 2, it is possible to perform one transmission (Excactry once) by combining these information and the packet ID correspondence information.

具体的には、QoS =2の場合、まず図45に示すようにセッションKが維持されている場合には、サーバ装置1(b2)からサブスクライバであるクライアント装置2(s1)へパケットIDが採番できてパケットID対応情報(pid_map_b2u )が記憶されるから、そのままパブリッシャからのpublish メッセージがクライアント装置2(s1)に到達しているはずである(sent=true になる)。仮にセッションKが切断された場合であっても、keep接続及び中途メッセージ情報(keep_mqtt )等に基づいてブローカであるサーバ装置1(b2)の制御により、送信しようとされていたpublish メッセージはクライアント装置2(s1)へ送達されるはずである。したがってQoS =2では送信を1回とするために、対応するパケットID対応情報が記憶されている場合には、保存メッセージ及びブローカ経由の配信先情報からの送信は回避されるべきである。そこでサーバ装置1(b2)は、データベース3(「store 」及び「store_target_broker_user」テーブル)から、自身(b2)宛てに、パケットID「0x125 」で、クライアント装置2(s1)向けに送信されたメッセージがあることを認識した場合に、ここからの送信をしないように処理を行なう。具体的にはサーバ装置1(b2)は自身宛のサーバ装置1(b1)からのメッセージのパケットID「0x125 」で識別情報「s1」を受信者としたパケットID対応情報のレコードがあるか否かを確認する。ブローカ間のセッションLが切断された場合には、再確立後MQTT上のやり取りが再開されず、pubrelメッセージを受信しないため、対応するパケットID対応情報のレコードが削除されずに残っているはずである。したがってサーバ装置1(b2)は、サーバ装置1(b1)から受信したメッセージのパケットIDと、そのメッセージをサブスクライバへ送信する際に用いるパケットIDとの対応関係を示すパケットID対応情報(pid_map_b2u )から、ブローカ経由の配信先情報に対応するレコード(source_broker_id==broker_id(b1), target_user_id=user_id(s1), source_pid==broker_pid(0x125))を検索により抽出できる。この場合、サーバ装置1(b2)は、データベース3に記憶してあるブローカ経由の配信先情報(「store_target_broker_user」)からの送信は行なわない。QoS =1の場合は、メッセージがデータベース3に記憶されていれば再送されていたのに対し、QoS =2では上述のように既に送信がされているはずである。このように同一メッセージに基づくpublish メッセージの重複を回避できる。なおサーバ装置1(b2)は、pubrelメッセージを受信できないために残っているブローカ経由の配信先情報と対応するパケットID対応情報(pid_map_b2u)を、その配信先情報と共にここで削除する。ブローカ経由の配信先情報に対応するレコードを検索で抽出できない場合は、サーバ装置1(b2)はブローカ経由の配信先情報からの送信が行ない、この場合、送信先のクライアント装置2からのpubrecメッセージ、pubcomp メッセージの受信により、配信先情報(「store_target_broker_user」)を削除する。   Specifically, in the case of QoS = 2, first, when the session K is maintained as shown in FIG. 45, the packet ID is taken from the server apparatus 1 (b2) to the client apparatus 2 (s1) as the subscriber. Since the packet ID correspondence information (pid_map_b2u) is stored, the publish message from the publisher should have arrived at the client device 2 (s1) as it is (sent = true). Even if the session K is disconnected, the publish message to be transmitted is controlled by the server device 1 (b2), which is the broker, based on the keep connection and the midway message information (keep_mqtt). Should be delivered to 2 (s1). Accordingly, in order to transmit once with QoS = 2, when the corresponding packet ID correspondence information is stored, transmission from the stored message and the delivery destination information via the broker should be avoided. Therefore, the server device 1 (b2) receives a message transmitted from the database 3 (“store” and “store_target_broker_user” table) to the client device 2 (s1) with the packet ID “0x125” addressed to itself (b2). When it is recognized that there is, processing is performed so as not to transmit from here. Specifically, the server device 1 (b2) has a packet ID correspondence information record with the packet ID “0x125” of the message from the server device 1 (b1) addressed to itself and the identification information “s1” as the receiver. To check. When the session L between brokers is disconnected, the exchange on MQTT is not resumed after re-establishment, and no pubrel message is received, so the corresponding packet ID correspondence information record should remain without being deleted. is there. Therefore, the server device 1 (b2) uses the packet ID correspondence information (pid_map_b2u) indicating the correspondence between the packet ID of the message received from the server device 1 (b1) and the packet ID used when transmitting the message to the subscriber. The records corresponding to the distribution destination information via the broker (source_broker_id == broker_id (b1), target_user_id = user_id (s1), source_pid == broker_pid (0x125)) can be extracted by searching. In this case, the server device 1 (b2) does not perform transmission from the delivery destination information (“store_target_broker_user”) stored in the database 3 via the broker. In the case of QoS = 1, if the message is stored in the database 3, it was retransmitted, but in the case of QoS = 2, it should have already been transmitted as described above. Thus, duplication of publish messages based on the same message can be avoided. The server device 1 (b2) deletes the packet ID correspondence information (pid_map_b2u) corresponding to the distribution destination information via the broker remaining because the pubrel message cannot be received together with the distribution destination information. If the record corresponding to the delivery destination information via the broker cannot be extracted by search, the server apparatus 1 (b2) performs transmission from the delivery destination information via the broker. In this case, the pubrec message from the destination client apparatus 2 When the pubcomp message is received, the delivery destination information (“store_target_broker_user”) is deleted.

図46は、図44に示した状態から、ブローカ間のセッションLが再確立された後の処理を示す。図46は更に、ブローカ間が切断されている間に、サブスクライバであるクライアント装置2(s1)が、サーバ装置1(b1)との間のセッションを切断し、サーバ装置1(b1)へ接続した場合の例を示している。   FIG. 46 shows processing after the session L between brokers is reestablished from the state shown in FIG. In FIG. 46, the client device 2 (s1), which is a subscriber, disconnected the session with the server device 1 (b1) and connected to the server device 1 (b1) while the brokers were disconnected. An example of the case is shown.

図46に示したケースでは、サーバ装置1は特定の処理を実行する。図47は、QoS =2におけるブローカ間のセッションの再確立後のメッセージ送信処理の一例を示すフローチャートである。図47の処理は例えば、図24のフローチャートに示した処理手順の内、ステップS309とステップS310の間に判断処理を加え、その判断処理でYESと判断されたときのみ行なう。判断処理とは、切断されていたセッションの相手のブローカに接続していたサブスクライバであるクライアント装置2が相手のブローカと通信接続を切断したか否かである。   In the case shown in FIG. 46, the server apparatus 1 executes a specific process. FIG. 47 is a flowchart illustrating an example of message transmission processing after re-establishing a session between brokers with QoS = 2. The processing in FIG. 47 is performed only when a determination process is added between step S309 and step S310 in the processing procedure shown in the flowchart of FIG. 24 and YES is determined in the determination process. The determination process is whether or not the client apparatus 2 which is a subscriber connected to the broker of the other party of the disconnected session has disconnected the communication connection with the other broker.

サーバ装置1の制御部は、データベース3(「store 」及び「store_target_broker_user」テーブル)に記憶されているブローカ経由の配信先情報を参照する(ステップS801)。ブローカ経由の配信先情報は、パブリッシャ側のブローカ(送信者)であるサーバ装置1(図40においてはサーバ装置1(b1))が記憶する情報である。制御部10は、ブローカ経由の配信先情報における送信完了しているか否かの情報(他のサーバ装置1からpubrecメッセージを受信しているか、[already_sent])、及び再送しているか否かの情報(再送時のパケットIDがNULLでないか)を参照する(ステップS802)。制御部10は、再送されているか否か(再送時のパケットIDがNULLでないか否か)を判断し(ステップS803)、再送されていると判断された場合(S803:YES)、送信が完了しているか否かの論理値を参照し、完了しているか否かを判断する(ステップS804)。送信が完了していると判断された場合(S804:YES)、制御部10は、配信先情報における再送時のパケットIDを用いてpubrelメッセージを送信し(ステップS805)、以後のMQTTモデルに基づくメッセージ処理を続行し、処理を終了する。   The control unit of the server apparatus 1 refers to the distribution destination information via the broker stored in the database 3 (“store” and “store_target_broker_user” table) (step S801). The distribution destination information via the broker is information stored in the server device 1 (the server device 1 (b1) in FIG. 40) which is the broker (sender) on the publisher side. The control unit 10 is information indicating whether or not transmission in the distribution destination information via the broker has been completed (whether a pubrec message has been received from another server device 1 or [already_sent]), and information regarding whether or not retransmission has been performed. Reference is made to (if the packet ID at the time of retransmission is not NULL) (step S802). The control unit 10 determines whether or not the packet has been retransmitted (whether or not the packet ID at the time of retransmission is NULL) (step S803). If it is determined that the packet has been retransmitted (S803: YES), the transmission is completed. Whether or not the process is completed is determined by referring to the logical value of whether or not the process is performed (step S804). If it is determined that the transmission has been completed (S804: YES), the control unit 10 transmits a pubrel message using the packet ID at the time of retransmission in the distribution destination information (step S805), and is based on the subsequent MQTT model. Continue message processing and end processing.

ステップS804にて送信が未完であると判断された場合(S804:NO)、制御部10は、配信先情報における再送時のパケットIDを用いてpublish メッセージを再送し(ステップS806)、以後のMQTTモデルに基づくメッセージ処理を続行し、処理を終了する。   When it is determined in step S804 that the transmission is incomplete (S804: NO), the control unit 10 retransmits the publish message using the packet ID at the time of retransmission in the distribution destination information (step S806), and the subsequent MQTT. Continue message processing based on the model and end processing.

ステップS803にて再送されていないと判断された場合(S803:NO)、制御部10は、ステップS801で参照した配信先情報と、送信者([source_user(broker)_id] )及び受信者([target_user(broker)_id])が同一であるパケットID対応情報のレコードをデータベース3から検索により抽出できるか否かを判断する(ステップS807)。   If it is determined in step S803 that it has not been retransmitted (S803: NO), the control unit 10 sends the distribution destination information referred to in step S801, the sender ([source_user (broker) _id]), and the receiver ([[ It is determined whether or not a record of packet ID correspondence information having the same target_user (broker) _id]) can be extracted from the database 3 by searching (step S807).

ステップS807にて検索により抽出できないと判断された場合は(S807:NO)、読み出された配信先情報に記憶されているパケットID対応情報の有無に応じた処理(情報が無い場合であっても実行するか否か)の可否を示す情報が、可を示すか否かを判断する(ステップS808)。   If it is determined in step S807 that the information cannot be extracted by the search (S807: NO), processing according to the presence / absence of the packet ID correspondence information stored in the read delivery destination information (when there is no information) It is determined whether or not the information indicating whether or not execution is also possible (step S808).

不可を示すと判断された場合(S808:NO)、制御部10は、処理をそのまま終了する。可を示すと判断された場合(S808:YES)、この場合、サブスクライバ側のブローカからパブリッシャ側のブローカへのpubrecメッセージの送信が未完了である(publish メッセージが送信されていない可能性がある)。制御部10は、新たなパケットIDを採番し(ステップS809)、採番したパケットIDを用いてpublish メッセージをサーバ装置1へ送信し(ステップS810)、処理を終了する。   When it is determined that it is impossible (S808: NO), the control unit 10 ends the process as it is. If it is determined that it is possible (S808: YES), in this case, transmission of the pubrec message from the subscriber-side broker to the publisher-side broker is incomplete (the publish message may not be transmitted). . The control unit 10 assigns a new packet ID (step S809), transmits a publish message to the server device 1 using the assigned packet ID (step S810), and ends the process.

ステップS807にて検索により抽出できると判断された場合は(S807:YES)、図45で説明したようにパケットID対応情報が存在しているので、他のブローカにおける制御により、サブスクライバへ配信がされるはずであるからそのサーバ装置1に処理を任せる。したがって制御部10は、処理をそのまま終了する。   If it is determined in step S807 that it can be extracted by the search (S807: YES), since the packet ID correspondence information exists as described in FIG. 45, it is distributed to the subscriber by the control of another broker. Therefore, the processing is left to the server device 1. Therefore, the control part 10 complete | finishes a process as it is.

図46を参照して具体的に説明する。サーバ装置1(b1)側ではブローカ間のメッセージについて、図24のフローチャートに示した処理手順の内で、puslish メッセージが残存していると判断される。(20)のタイミングにおけるpublish メッセージに対するpubrecメッセージを受信していないからである。ただしこのケースでは、残存しているpublish メッセージに基づくサブスクライバへのメッセージの送信は、再確立させたサーバ装置1(b2)を経由して行なうか否かは不明である。サーバ装置1(b2)がクライアント装置2(s1)と切断されているので、サーバ装置1(b1)は、ブローカ間のメッセージについて図47の処理を実行する。図46の例では、パケットID対応情報が記憶されているので(S807)、は特に何も送信されず、処理が終了する。   This will be specifically described with reference to FIG. On the server device 1 (b1) side, regarding the message between brokers, it is determined that the push message remains in the processing procedure shown in the flowchart of FIG. This is because the pubrec message for the publish message at the timing (20) has not been received. However, in this case, it is unclear whether or not the message transmission to the subscriber based on the remaining publish message is performed via the reestablished server device 1 (b2). Since the server apparatus 1 (b2) is disconnected from the client apparatus 2 (s1), the server apparatus 1 (b1) executes the process of FIG. 47 for messages between brokers. In the example of FIG. 46, since packet ID correspondence information is stored (S807), nothing is transmitted and the process ends.

なお図46に示した例においてサーバ装置1(b1)は、クライアント装置2(s1)がサーバ装置1(b1)へセッション確立をリクエストし、これを承諾するとデータベース3における接続先情報を識別情報「b1」に書き換える。この後同期処理が実行され、サーバ装置1(b1及びb2)間で接続情報が共有される。サーバ装置1(b1)は、状態情報を記憶しているクライアント装置2の識別情報「s1」と、データベース3に記憶されている各クライアント装置2の接続先情報(「connections 」)における識別情報「s1」とを照合し(図24のS309)、接続先情報でも自身が接続先であると判断する(S310:YES)。そしてサーバ装置1(b1)は、ステップS311−S313の処理において、後述するようにサーバ装置1(b2)がデータベース3に記憶(移動)したパケットID対応情報にて、自身を送信者とし、接続してきたクライアント装置2(s1)を受信者とするレコードを検索し、検索されるとそのレコードに記憶されている送信完了の論理値([sent])を参照する。論理値が送信完了である場合、そのレコードの受信者向けのパケットID([target_pid])を用いてpubrelメッセージを送信し、送信完了でない場合、同パケットIDを用いてpublish メッセージを再送することができる。   In the example shown in FIG. 46, in the server apparatus 1 (b1), when the client apparatus 2 (s1) requests the server apparatus 1 (b1) to establish a session and accepts this, the connection destination information in the database 3 is identified with the identification information “ Rewrite as “b1”. Thereafter, synchronization processing is executed, and connection information is shared between the server apparatuses 1 (b1 and b2). The server apparatus 1 (b1) has the identification information “s1” of the client apparatus 2 storing the state information and the identification information “connections” of each client apparatus 2 stored in the database 3. s1 ”(S309 in FIG. 24), and it is determined that the connection destination information itself is the connection destination (S310: YES). Then, the server device 1 (b1) establishes itself as a sender in the packet ID correspondence information stored (moved) in the database 3 by the server device 1 (b2) in the processing of steps S311 to S313 as described later. The client apparatus 2 (s1) that has received the request is searched for a record, and when the record is searched, the logical value ([sent]) of transmission completion stored in the record is referred to. If the logical value is transmission complete, the pubrel message is transmitted using the packet ID ([target_pid]) for the recipient of the record. If the transmission is not complete, the publish message may be retransmitted using the packet ID. it can.

図46で示す例においてサーバ装置1(b2)側では、サーバ装置1(b1)とのセッションを再確立すると(図24、S307)、同期処理を行なう(S308)。サーバ装置1(b2)は、状態情報とデータベース3に記憶されている各クライアント装置2の接続先情報(「connections 」)における識別情報「s1」を照合し(S309)、自身が接続先でないと判断する(S310:NO)。サーバ装置1(b2)は、クライアント装置2(s1)についての状態情報を削除する(S311)。そしてサーバ装置1(b2)は、図43のフローチャートに示した手順にしたがい、クライアント装置2(s1)との関係におけるパケットID対応情報(図中のpid_map_b2u )をデータベース3に記憶(移動)する(S604)。その後、再度通信接続してきていないと判断されるため(S606:NO)、以後のクライアント装置2(s1)向けの処理はサーバ装置1(b1)側に任される。   In the example shown in FIG. 46, on the server device 1 (b2) side, when a session with the server device 1 (b1) is re-established (FIG. 24, S307), synchronization processing is performed (S308). The server device 1 (b2) collates the identification information “s1” in the connection destination information (“connections”) of each client device 2 stored in the database 3 with the status information (S309), and if it is not the connection destination itself Judgment is made (S310: NO). The server apparatus 1 (b2) deletes the status information about the client apparatus 2 (s1) (S311). Then, the server device 1 (b2) stores (moves) the packet ID correspondence information (pid_map_b2u in the drawing) in the database 3 in relation to the client device 2 (s1) according to the procedure shown in the flowchart of FIG. S604). Thereafter, since it is determined that the communication connection has not been made again (S606: NO), subsequent processing for the client device 2 (s1) is left to the server device 1 (b1) side.

このように、MQTTモデルにおける到達保証のメッセージのやり取りの途中でブローカ間のセッションが切断された場合であっても、パブリッシャであるクライアント装置2からQoS =2が指定されたメッセージの到達保証をクライアント装置2からブローカまでのセッションのみならず、サブスクライバであるクライアント装置2までの経路においてQoS =2とすることができる。   As described above, even when the session between brokers is disconnected during the exchange of the message for guaranteeing the arrival in the MQTT model, the client guarantees the arrival of the message with QoS = 2 specified by the client device 2 as the publisher. QoS = 2 can be set not only in the session from the apparatus 2 to the broker but also in the path to the client apparatus 2 as a subscriber.

(5)QoS =2、ブローカダウン保証
ブローカがダウンした場合もメッセージの到達を保証するという前提において、(4)同様に、経路である全てのセッションにてQoS が「2」となるQoS =2が指定されたpublish メッセージのサブスクライバまでの到達について説明する。なお以下の説明でも(4)同様に、当該メッセージのトピックについてサブスクライバであるクライアント装置2がQoS として「2」以外を指定している場合については、説明を省略する。
(5) QoS = 2, Broker Down Guarantee On the premise that message arrival is guaranteed even if the broker is down, QoS is “2” in all sessions that are routes, as in (4). Describes reaching a subscriber of a publish message with a specified. In the following description, similarly to (4), the description is omitted when the client apparatus 2 as a subscriber specifies a QoS other than “2” for the topic of the message.

図48は、QoS =2でブローカダウンを保証する際の処理を示す図である。図48で示す装置の構成は、ブローカダウンを保証しない場合について説明した図38で示した例と同一である。図48と図38とを比較すると明らかであるように、差異はパケットID対応情報の記憶先である。QoS =2で更にブローカダウンを保証する場合、keep接続におけるデータベース3(store, store_target )の記憶に加え、各サーバ装置1がパケットID対応情報を一時記憶部13に一時記憶するのではなく、いずれのブローカの情報であるかを対応付けてデータベース3に記憶し、復旧後にパケットIDの異なるセッション間の一時記憶を復旧することを可能にする。   FIG. 48 is a diagram showing processing when guaranteeing broker down with QoS = 2. The configuration of the apparatus shown in FIG. 48 is the same as the example shown in FIG. 38 for explaining the case where broker down is not guaranteed. As is clear when FIG. 48 is compared with FIG. 38, the difference is the storage destination of the packet ID correspondence information. When guaranteeing further broker down with QoS = 2, in addition to storing the database 3 (store, store_target) in keep connection, each server device 1 does not temporarily store the packet ID correspondence information in the temporary storage unit 13, Is stored in the database 3 in association with each other, and it is possible to recover temporary storage between sessions having different packet IDs after recovery.

(5.1)正常運用時
ブローカがダウンした場合にメッセージの到達を保証する場合、ダウンしたことを自身で検知できないので、ダウンした場合の処理に切り替えるといったことができない。この場合サーバ装置1は、一時記憶して用いる情報(送信バッファ、及びパケットID対応情報)、データベース3に記憶して用いる。QoS =2の場合、ブローカダウンを保証する場合もサーバ装置1は基本的に、図39のフローチャートに示した処理手順を実行する。ただし、パケットID対応情報の記憶先がデータベース3であることと、QoS =1の場合について説明した図29のフローチャートで示したように、publish メッセージを送信する前に、keep接続しているクライアント装置2が自身に接続している場合は必ず、データベース3(「store 」及び「store_target」又は「store_target_broker 」)にメッセージを記憶する処理を実行する。即ちサーバ装置1は、図29のフローチャートに示した処理手順の内、S221、S222、S223−S225、S226、S227、S228−S229の処理を、図39のフローチャートにおけるpublish メッセージの送信処理(S508、S518)の前に行なう。なお図29におけるpubackメッセージに関する処理に関してはpubrecメッセージの処理に置換される。
(5.1) During normal operation When the message is guaranteed to arrive when the broker is down, it cannot be detected by itself, so it cannot be switched to the processing when it is down. In this case, the server apparatus 1 stores and uses information (transmission buffer and packet ID correspondence information) temporarily stored and used in the database 3. In the case of QoS = 2, the server apparatus 1 basically executes the processing procedure shown in the flowchart of FIG. 39 even when the broker down is guaranteed. However, as shown in the flowchart of FIG. 29 that describes the case where the storage destination of the packet ID correspondence information is the database 3 and the case of QoS = 1, the client device connected with keep before sending the publish message When 2 is connected to itself, a process of storing a message in the database 3 (“store” and “store_target” or “store_target_broker”) is executed. That is, the server apparatus 1 performs the processing of S221, S222, S223-S225, S226, S227, and S228-S229 in the processing procedure shown in the flowchart of FIG. Performed before S518). Note that the processing relating to the puback message in FIG. 29 is replaced with the processing of the pubrec message.

図48に示すQoS =2の場合でのパケットID対応情報は、記憶先がデータベース3であって、また具体的内容(記憶処理を行なったサーバ装置1の識別情報(broker_id )が最初に対応付けられて記憶)が異なる以外は、ダウンを保証外とする場合の処理手順と同様である(図38を参照した(4.1)における説明)。   The packet ID correspondence information in the case of QoS = 2 shown in FIG. 48 is that the storage destination is the database 3, and the specific content (identification information (broker_id) of the server device 1 that performed the storage processing) is first associated. The processing procedure is the same as that in the case where down is not guaranteed (explained in (4.1) with reference to FIG. 38) except that the storage is different.

(5.2)切断時
ブローカがダウンした場合もQoS =2が指定されたメッセージの到達を保証する場合において、切断又はダウンが発生したケースについて具体例を挙げて説明する。基本的に、図48で示したように、パケットID対応情報の記憶先が常にデータベース3であることを除いては、ダウンを保証しない場合の処理と同様である。ブローカダウン時もメッセージの到達をQoS =2で保証する場合には、publish メッセージの送信の都度、データベース3に事前に保存メッセージとして記憶され、完了する都度に削除されると共に、その際のパケットID対応情報もデータベース3に記憶されるから、ダウンした場合も復旧時にデータベース3から、それらの情報を参照して状態情報を復旧することができる。この場合具体的にはサーバ装置1は復旧時に、(3)のQoS =1におけるダウン保証の説明で示した図34のフローチャートの処理手順を実行する。このとき、ステップS409の対応メッセージは、pubcomp メッセージの受信に読み替えられる。つまり記憶された配信先情報及び保存メッセージは、サーバ装置1におけるpubcomp メッセージの受信をトリガに削除される。
(5.2) At disconnection A case where disconnection or down occurs in the case of guaranteeing the arrival of a message in which QoS = 2 is specified even when the broker is down will be described with a specific example. Basically, as shown in FIG. 48, the processing is the same as that in the case where down is not guaranteed except that the storage destination of the packet ID correspondence information is always the database 3. When QoS = 2 guarantees message arrival even when the broker is down, it is stored as a stored message in the database 3 in advance every time a publish message is sent, and is deleted every time it is completed. Since the correspondence information is also stored in the database 3, even when it is down, the state information can be recovered from the database 3 by referring to the information at the time of recovery. In this case, specifically, the server apparatus 1 executes the processing procedure of the flowchart of FIG. 34 shown in the description of the down guarantee in QoS = 1 in (3) at the time of recovery. At this time, the corresponding message in step S409 is read as reception of a pubcomp message. That is, the stored delivery destination information and the stored message are deleted when the server apparatus 1 receives the pubcomp message.

ブローカダウン時もメッセージの到達をQoS =2で保証する場合、メッセージの送受信に係る多くの情報をデータベース3に記憶することになる。データベース3への更新及び削除の処理は、時間を要するものである。したがってこのケースでは特に、データベース3をKVSで構成し、全てのイベントを書き込みとすることで処理速度を向上させることが期待できる。   When guaranteeing the arrival of a message with QoS = 2 even when the broker is down, a lot of information related to the transmission / reception of the message is stored in the database 3. The process of updating and deleting the database 3 takes time. Therefore, in this case, in particular, it is expected that the processing speed can be improved by configuring the database 3 with KVS and writing all the events.

このように、本実施の形態1における通信システム100では、ブローカダウンを考慮した上でパブリッシャからサブスクライバまでのメッセージの到達保証を実現する。完全なる到達保証を実現するには、各ブローカであるサーバ装置1が全てをデータベース3に記憶することで実現することは可能であるが、処理速度が低下し、Pub/Sub 型メッセージ送受信システムの負荷の軽さの利点を享受できない。本実施の形態における通信システム100では、システムを利用するユーザのクライアント装置2が、ブローカへ通信接続する際(keep)、そしてブローカ起動時、即ちサブスクライバから接続するブローカを選択する際(ブローカダウン時保証の有無)、ブローカへサブスクライブを実行する際(サブスクライブ時のQoS の指定)、更にメッセージを送信する際に(パブリッシュ時のQoS の指定)、各々で保証レベルを選択することが可能である。   As described above, the communication system 100 according to the first embodiment realizes message arrival guarantee from the publisher to the subscriber in consideration of broker down. Although it is possible to achieve complete arrival guarantee by storing all of the server devices 1 as brokers in the database 3, the processing speed is reduced, and the Pub / Sub message transmission / reception system The advantage of light load cannot be enjoyed. In the communication system 100 according to the present embodiment, when a client device 2 of a user who uses the system establishes a communication connection to a broker (keep) and starts a broker, that is, selects a broker to be connected from a subscriber (when the broker is down). Guarantee level), when subscribing to a broker (specifying QoS when subscribing), and when sending a message (specifying QoS when publishing), it is possible to select a guarantee level for each. is there.

本開示の実施形態はすべての点で例示であって、制限的なものではないと考えられるべきである。本発明の範囲は、上記した意味ではなく、特許請求の範囲によって示され、特許請求の範囲と均等の意味及び範囲内でのすべての変更が含まれることが意図される。   The embodiments of the present disclosure are to be considered in all respects as illustrative and not restrictive. The scope of the present invention is defined by the terms of the claims, rather than the meanings described above, and is intended to include any modifications within the scope and meaning equivalent to the terms of the claims.

1 サーバ装置(ブローカ)
10 制御部
11 第1記憶部
1P サーバプログラム
12 第2記憶部(データベース)
13 一時記憶部
14 通信部
2 クライアント装置(パブリッシャ/サブスクライバ)
20 制御部
21 記憶部
22 通信部
3 データベース
N ネットワーク
1 Server device (broker)
DESCRIPTION OF SYMBOLS 10 Control part 11 1st memory | storage part 1P Server program 12 2nd memory | storage part (database)
13 Temporary Storage Unit 14 Communication Unit 2 Client Device (Publisher / Subscriber)
20 control unit 21 storage unit 22 communication unit 3 database N network

Claims (8)

パブリッシュ/サブスクライブ型のメッセージを、パブリッシャ又はサブスクライバである複数のクライアント装置との間を仲介する1又は複数のサーバ装置が送受信する通信方法において、
前記サーバ装置は、
パブリッシャであるクライアント装置から受信したメッセージを、サブスクライバであるクライアント装置へ、多くとも1回到達すべきとする第0次到達保証、少なくとも1回到達すべきとする第1次到達保証、必ず1回到達すべきとする第2次到達保証のいずれで到達させるかの到達保証属性の選択をメッセージ毎に受け付け、
自身が処理不可状態となった場合でもメッセージの到達を保証すべきか否かの動作保証属性の選択を受け付け、
到達保証属性の選択及び動作保証の選択の組み合わせに応じて、クライアント装置又は他のサーバ装置から受信したメッセージに対する受信処理を切り替える
通信方法。
In a communication method in which a publish / subscribe type message is transmitted and received by one or a plurality of server devices that mediate between a plurality of client devices that are publishers or subscribers.
The server device
0th order arrival guarantee that a message received from a client device that is a publisher should reach a client device that is a subscriber at most once, first arrival guarantee that a message should be reached at least once, always once Accepting for each message the selection of the arrival guarantee attribute to be reached in which of the second arrival guarantees to be reached,
Accepting the selection of the operation guarantee attribute for whether or not the message should be guaranteed even if it becomes unprocessable
A communication method for switching reception processing for a message received from a client device or another server device in accordance with a combination of selection of arrival guarantee attribute and selection of operation guarantee.
前記サーバ装置は、
前記第1次到達保証が選択されたメッセージの送信先に他のサーバ装置が含まれる場合、該他のサーバ装置から送信される受領確認を受信してから、パブリッシャへ受領確認を返信し、
前記第1次到達保証が選択されたメッセージの送信先に他のサーバ装置が含まれない場合、前記メッセージの送信先への送信処理後に、送信元へ受領確認を返信する
請求項1の通信方法。
The server device
If another server device is included in the transmission destination of the message for which the first arrival guarantee has been selected, a receipt confirmation transmitted from the other server device is received, and then a receipt confirmation is returned to the publisher.
2. The communication method according to claim 1, wherein, when a destination of the message for which the first arrival guarantee is selected does not include another server device, a receipt confirmation is returned to the source after the transmission processing to the destination of the message. .
前記サーバ装置は、不揮発性の第1記憶媒体を用い、
前記第1次到達保証が選択されたメッセージの到達を、前記処理不可状態となった場合でも保証すべきと選択された場合、メッセージを送信する前に、該メッセージと、メッセージの配信先、該配信先からの受領確認の有無を含む配信先情報とを前記第1記憶媒体に記憶する
請求項2の通信方法。
The server device uses a nonvolatile first storage medium,
If it is selected that the arrival of the message for which the first arrival guarantee is selected should be guaranteed even when the processing is disabled, the message, the message delivery destination, The communication method according to claim 2, wherein distribution destination information including presence / absence of receipt confirmation from the distribution destination is stored in the first storage medium.
前記サーバ装置は、揮発性の第2記憶媒体を用い、
前記第2次到達保証が選択されたメッセージの送信先に他のサーバ装置が含まれる場合、前記メッセージの受信に使用された第1識別情報と、該他のサーバ装置への送信に使用する第2識別情報との第1の対応関係を前記第2記憶媒体へ記憶し、
前記他のサーバ装置から送信される受領確認を受信してから、送信元へ前記第2記憶媒体へ記憶してある第1識別情報を使用して受領確認を返信し、
前記第1次到達保証が選択されたメッセージの送信先に他のサーバ装置が含まれない場合、前記メッセージの受信に使用された第3識別情報と、該クライアント装置への送信に使用する第4識別情報との第2の対応関係を前記第2記憶媒体へ記憶し、前記メッセージの送信処理後に、前記第2記憶媒体に記憶してある第3識別情報を用いて受領確認を返信する
請求項1の通信方法。
The server device uses a volatile second storage medium,
When another server apparatus is included in the transmission destination of the message for which the second arrival guarantee is selected, the first identification information used for receiving the message and the first identification information used for transmission to the other server apparatus Storing the first correspondence with the two identification information in the second storage medium;
After receiving the receipt confirmation transmitted from the other server device, the receipt confirmation is returned to the transmission source using the first identification information stored in the second storage medium,
When no other server device is included in the transmission destination of the message for which the first arrival guarantee is selected, the third identification information used for receiving the message and the fourth identification information used for transmission to the client device The second correspondence relationship with the identification information is stored in the second storage medium, and after the message transmission process, a receipt confirmation is returned using the third identification information stored in the second storage medium. 1 communication method.
前記サーバ装置は、不揮発性の第1記憶媒体を用い、
前記第2次到達保証が選択されたメッセージの到達を、前記処理不可状態となった場合でも保証すべきと選択された場合、
前記第1及び第2の対応関係を前記第1記憶媒体に記憶し、
メッセージを送信する前に、該メッセージと、メッセージの配信先、該配信先からの受領確認の有無を含む配信先情報とを前記第1記憶媒体に記憶する
請求項4の通信方法。
The server device uses a nonvolatile first storage medium,
When it is selected that the arrival of the message for which the second arrival guarantee has been selected should be guaranteed even when the processing is disabled,
Storing the first and second correspondences in the first storage medium;
5. The communication method according to claim 4, wherein the message, the delivery destination of the message, and delivery destination information including presence / absence of receipt confirmation from the delivery destination are stored in the first storage medium before the message is transmitted.
パブリッシュ/サブスクライブ型のメッセージの送受信を仲介する通信装置において、
受信したメッセージを、サブスクライバへ多くとも1回到達すべきとする第0次到達保証、少なくとも1回到達すべきとする第1次到達保証、必ず1回到達すべきとする第2次到達保証のいずれで到達させるかの到達保証属性の選択を受け付ける第1の到達保証属性受付部と、
自身が処理不可状態となった場合でもメッセージの到達を保証すべきか否かの動作保証属性の選択を受け付ける動作保証属性受付部と、
到達保証属性の選択及び動作保証の選択の組み合わせに応じて、受信したメッセージに対する受信処理を切り替える受信処理切替部と
を備える通信装置。
In a communication device that mediates transmission / reception of publish / subscribe type messages,
The zeroth arrival guarantee that the received message should reach the subscriber at most once, the first arrival guarantee that the message should reach at least once, and the second arrival guarantee that the message must be reached once A first arrival guarantee attribute accepting unit for accepting selection of an arrival guarantee attribute to be reached;
An operation guarantee attribute accepting unit that accepts a selection of an operation guarantee attribute as to whether or not the arrival of a message should be guaranteed even when the process becomes unprocessable,
A communication apparatus comprising: a reception process switching unit that switches a reception process for a received message according to a combination of selection of an arrival guarantee attribute and selection of an operation guarantee.
通信部を備えるコンピュータに、パブリッシュ/サブスクライブ型のメッセージの送受信を実行させるコンピュータプログラムにおいて、
前記コンピュータに、
受信したメッセージを、サブスクライバへ多くとも1回到達すべきとする第0次到達保証、少なくとも1回到達すべきとする第1次到達保証、必ず1回到達すべきとする第2次到達保証のいずれで到達させるかの到達保証属性の選択を受け付ける処理、
自身が処理不可状態となった場合でもメッセージの到達を保証すべきか否かの動作保証属性の選択を受け付ける処理、及び
到達保証属性の選択及び動作保証の選択の組み合わせに応じて、受信したメッセージに対する受信処理を切り替える処理
を実行させるコンピュータプログラム。
In a computer program for causing a computer including a communication unit to execute transmission / reception of a publish / subscribe type message,
In the computer,
The zeroth arrival guarantee that the received message should reach the subscriber at most once, the first arrival guarantee that the message should reach at least once, and the second arrival guarantee that the message must be reached once A process for accepting the selection of the arrival guarantee attribute to be reached,
Depending on the combination of the processing that accepts the selection of the operation guarantee attribute to determine whether or not the message should be guaranteed even if it becomes unprocessable, and the combination of the selection of the arrival guarantee attribute and the operation guarantee A computer program that executes processing to switch reception processing.
パブリッシュ/サブスクライブ型のメッセージをパブリッシャ又はサブスクライバとして送受信する複数のクライアント装置と、該複数のクライアント装置の間のメッセージの送受信を仲介する1又は複数のサーバ装置とを含む通信システムにおいて、
前記サーバ装置は、
パブリッシャであるクライアント装置から受信したメッセージを、サブスクライバであるクライアント装置へ、多くとも1回到達すべきとする第0次到達保証、少なくとも1回到達すべきとする第1次到達保証、必ず1回到達すべきとする第2次到達保証のいずれで到達させるかの到達保証属性の選択を受け付ける第1の到達保証属性受付部と、
自身が処理不可状態となった場合でもメッセージの到達を保証すべきか否かの動作保証属性の選択を受け付ける動作保証属性受付部と、
到達保証属性の選択及び動作保証の選択の組み合わせに応じて、クライアント装置又は他のサーバ装置から受信したメッセージに対する受信処理を切り替える受信処理切替部と
を含み、
前記クライアント装置は、
通信接続するサーバ装置に対し前記動作保証属性を選択する第1選択部と、
メッセージを送信又は受信する場合に、該メッセージの到達保証属性を選択する第2選択部と
を備える通信システム。
In a communication system including a plurality of client devices that transmit and receive publish / subscribe messages as publishers or subscribers, and one or a plurality of server devices that mediate transmission and reception of messages between the plurality of client devices.
The server device
0th order arrival guarantee that a message received from a client device that is a publisher should reach a client device that is a subscriber at most once, first arrival guarantee that a message should be reached at least once, always once A first arrival guarantee attribute accepting unit that accepts selection of an arrival guarantee attribute to be reached in which of the second arrival guarantees to be reached;
An operation guarantee attribute accepting unit that accepts a selection of an operation guarantee attribute as to whether or not the arrival of a message should be guaranteed even when the process becomes unprocessable,
A reception process switching unit that switches a reception process for a message received from the client apparatus or another server apparatus according to a combination of the selection of the arrival guarantee attribute and the selection of the operation guarantee, and
The client device is
A first selection unit that selects the operation guarantee attribute for a server device to be connected for communication;
A communication system comprising: a second selection unit that selects an arrival guarantee attribute of a message when the message is transmitted or received.
JP2018060853A 2018-03-27 2018-03-27 Communication methods, communication systems, communication devices and computer programs Active JP6857151B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2018060853A JP6857151B2 (en) 2018-03-27 2018-03-27 Communication methods, communication systems, communication devices and computer programs

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2018060853A JP6857151B2 (en) 2018-03-27 2018-03-27 Communication methods, communication systems, communication devices and computer programs

Publications (2)

Publication Number Publication Date
JP2019176275A true JP2019176275A (en) 2019-10-10
JP6857151B2 JP6857151B2 (en) 2021-04-14

Family

ID=68167355

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2018060853A Active JP6857151B2 (en) 2018-03-27 2018-03-27 Communication methods, communication systems, communication devices and computer programs

Country Status (1)

Country Link
JP (1) JP6857151B2 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR102384614B1 (en) * 2020-11-30 2022-04-08 경북대학교 산학협력단 Smart phill box control system using broker server in restricted communication environments

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR102384614B1 (en) * 2020-11-30 2022-04-08 경북대학교 산학협력단 Smart phill box control system using broker server in restricted communication environments

Also Published As

Publication number Publication date
JP6857151B2 (en) 2021-04-14

Similar Documents

Publication Publication Date Title
US9577920B2 (en) Communication system, control device, node, processing rule setting method and program
US7882253B2 (en) Real-time publish-subscribe system
CN110297801A (en) A just transaction semantics for transaction system based on fault-tolerant FPGA
CN101141301B (en) Method and apparatus for transaction recovery
KR20120136371A (en) Managing network communications between network nodes and stream transport protocol
US20080159325A1 (en) System and method for tcp high availability
CN102111419B (en) Message middleware-based client automatic reconnection method
US20080010299A1 (en) File management system
TWI454917B (en) Access control method, access control device and access control program
CN108390950A (en) A kind of information push method, device and equipment
CN111787079B (en) Communication method, device, server, system and medium based on communication group
JP6857151B2 (en) Communication methods, communication systems, communication devices and computer programs
TWI743802B (en) File transmission/reception device
KR20060112350A (en) Notification system and method using messenger
JP5509564B2 (en) Message transmission method and program
JP3608905B2 (en) Data communication system and data communication method
JP5029685B2 (en) Backup device
CN105656959A (en) Multi-terminal PUB/SUB (Publish/Subscribe) message synchronization method based on routing mechanism
JP3839967B2 (en) Broadcast communication method and communication apparatus
JP3006469B2 (en) Message double feed check system
JP5187595B2 (en) Communication device and communication device redundancy method
KR102279601B1 (en) Method Of Gateway For DDS
JP4038406B2 (en) Event sharing system, host, event sharing method, and event sharing program
WO2013073000A1 (en) Relay backup device and relay control method
JP2000347965A (en) System and method for mobile communication

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20190917

A977 Report on retrieval

Free format text: JAPANESE INTERMEDIATE CODE: A971007

Effective date: 20200819

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20200901

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20201029

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20210224

A521 Request for written amendment filed

Free format text: JAPANESE INTERMEDIATE CODE: A523

Effective date: 20210302

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20210316

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20210319

R150 Certificate of patent or registration of utility model

Ref document number: 6857151

Country of ref document: JP

Free format text: JAPANESE INTERMEDIATE CODE: R150

R250 Receipt of annual fees

Free format text: JAPANESE INTERMEDIATE CODE: R250