TWI728445B - Message redirecting method and application programming interface gateway - Google Patents

Message redirecting method and application programming interface gateway Download PDF

Info

Publication number
TWI728445B
TWI728445B TW108130909A TW108130909A TWI728445B TW I728445 B TWI728445 B TW I728445B TW 108130909 A TW108130909 A TW 108130909A TW 108130909 A TW108130909 A TW 108130909A TW I728445 B TWI728445 B TW I728445B
Authority
TW
Taiwan
Prior art keywords
message
browser
instance
user
microservice
Prior art date
Application number
TW108130909A
Other languages
Chinese (zh)
Other versions
TW202110139A (en
Inventor
廖尉辰
Original Assignee
中華電信股份有限公司
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 中華電信股份有限公司 filed Critical 中華電信股份有限公司
Priority to TW108130909A priority Critical patent/TWI728445B/en
Publication of TW202110139A publication Critical patent/TW202110139A/en
Application granted granted Critical
Publication of TWI728445B publication Critical patent/TWI728445B/en

Links

Images

Landscapes

  • Data Exchanges In Wide-Area Networks (AREA)
  • Computer And Data Communications (AREA)

Abstract

The disclosure provides a message redirecting method and an application programming interface gateway instance, which is suitable a first instance deployed in a microservice system, wherein the first instance is an application programming interface gateway instance. The method includes: detecting whether a first message appears in a specific topic of a message queue in the microservice system, wherein the first message encapsulates a first message content and a first recipient identity; determining whether a first user corresponding to the first recipient identity has been registered on the first instance through a first browser; in response to determining that the first user has been registered on the first instance, redirecting the first message content to the first browser through a first Websocket connection between the first browser and the first instance.

Description

訊息轉導方法及應用程式介面閘道器 Message transfer method and application program interface gateway

本發明是有關於一種微服務系統的運作方法,且特別是有關於一種微服務系統中的訊息轉導方法及應用程式介面(application programming interface,API)閘道器實例(instance)。 The present invention relates to an operating method of a microservice system, and particularly relates to a message transduction method and an application programming interface (API) gateway instance in the microservice system.

一般而言,瀏覽器與網頁伺服器所建立之WebSocket連線為一對一的連線。然而,在支援高可用性的微服務系統架構下,將架設有多個閘道器(例如API閘道器實例)。在此情況下,可能面臨每次的瀏覽器請求皆傳送到不同的API閘道器實例的問題。並且,其他微服務欲發送給瀏覽器的訊息也可能透過不同的API閘道器實例轉送,此時將面臨WebSocket訊息的同步問題。 Generally speaking, the WebSocket connection established by the browser and the web server is a one-to-one connection. However, under a microservice system architecture that supports high availability, multiple gateways (such as API gateway instances) will be set up. In this case, you may face the problem that each browser request is sent to a different API gateway instance. In addition, the messages that other microservices want to send to the browser may also be forwarded through different API gateway instances. At this time, they will face the synchronization problem of WebSocket messages.

有鑑於此,本發明提供一種訊息轉導方法及API閘道器,其可用以解決上述技術問題。 In view of this, the present invention provides a message transduction method and API gateway, which can be used to solve the above technical problems.

本發明提供一種訊息轉導方法,適於部署於一微服務系 統中的一第一實例,其中第一實例為一應用程式介面閘道器實例,包括:偵測微服務系統中一訊息佇列的一特定主題中是否出現一第一訊息,其中第一訊息封裝有一第一訊息內容及一第一接收者身分;解封裝第一訊息以取得第一訊息內容及第一接收者身分;判斷對應於第一接收者身分的一第一使用者是否已透過一第一瀏覽器註冊於第一實例上;反應於判定第一使用者已註冊於第一實例上,透過第一實例與第一瀏覽器之間的一第一Websocket連線將第一訊息內容轉導至第一瀏覽器。 The present invention provides a message transduction method suitable for deployment in a microservice system A first example in the system, where the first example is an application programming interface gateway example, including: detecting whether a first message appears in a specific topic in a message queue in a microservice system, where the first message Encapsulate a first message content and a first recipient identity; unpack the first message to obtain the first message content and first recipient identity; determine whether a first user corresponding to the first recipient identity has passed a The first browser is registered on the first instance; in response to the determination that the first user has been registered on the first instance, the content of the first message is transferred through a first Websocket connection between the first instance and the first browser Lead to the first browser.

本發明提供一種應用程式介面閘道器,其部署於一微服務系統中,包括訊息佇列模組、註冊模組及Websocket模組。訊息佇列模組經配置以:偵測微服務系統中一訊息佇列的一特定主題中是否出現一第一訊息,其中第一訊息封裝有一第一訊息內容及一第一接收者身分;解封裝第一訊息以取得第一訊息內容及第一接收者身分。註冊模組判斷對應於第一接收者身分的一第一使用者是否已透過一第一瀏覽器註冊於第一實例上。Websocket模組在註冊模組判定第一使用者已註冊於第一實例上後,透過第一實例與第一瀏覽器之間的一第一Websocket連線將第一訊息內容轉導至第一瀏覽器。 The invention provides an application program interface gateway, which is deployed in a microservice system and includes a message queue module, a registration module and a Websocket module. The message queue module is configured to detect whether a first message appears in a specific subject of a message queue in the microservice system, wherein the first message encapsulates a first message content and a first recipient identity; Encapsulate the first message to obtain the content of the first message and the identity of the first recipient. The registration module determines whether a first user corresponding to the identity of the first recipient has been registered on the first instance through a first browser. After the registration module determines that the first user is registered on the first instance, the Websocket module forwards the content of the first message to the first browser through a first Websocket connection between the first instance and the first browser Device.

基於上述,本發明的API閘道器實例可在偵測到特定主題中出現新的封裝訊息之後,可將其解封裝以取得其中的接收者身分。接著,若某API閘道器實例判定此接收者身分的使用者已註冊於自身上,則此API閘道器實例可透過已建立的Websocket 連線將訊息內容予以轉導。 Based on the above, the API gateway example of the present invention can decapsulate a new encapsulated message in a specific subject after detecting the new encapsulated message to obtain the recipient's identity. Then, if an API gateway instance determines that the user of the recipient identity has been registered on itself, then this API gateway instance can use the established Websocket Connect to relay the content of the message.

為讓本發明的上述特徵和優點能更明顯易懂,下文特舉實施例,並配合所附圖式作詳細說明如下。 In order to make the above-mentioned features and advantages of the present invention more comprehensible, the following specific embodiments are described in detail in conjunction with the accompanying drawings.

100:微服務系統 100: Microservice system

11~1N:API閘道器實例 11~1N: API gateway example

111:請求處理模組 111: request processing module

112:訊息佇列模組 112: Message Queue Module

113:註冊模組 113: Registered Module

114:HTTP請求轉導模組 114: HTTP request transduction module

115:Websocket模組 115: Websocket module

120:訊息佇列 120: Message Queue

130:微服務 130: microservices

S210~S250:步驟 S210~S250: steps

圖1是依據本發明之一實施例繪示的微服務系統示意圖。 Fig. 1 is a schematic diagram of a micro service system according to an embodiment of the present invention.

圖2是依據本發明之一實施例繪示的訊息轉導方法。 Fig. 2 is a message transduction method according to an embodiment of the present invention.

概略而言,本發明提供一種基於訊息佇列實作微服務架構下的高可用性應用程式介面閘道器的系統與方法,解決瀏覽器與應用程式介面閘道器間透過WebSocket連線時的訊息同步問題、跨網域的WebSocket連線橋接問題以及跨網域超文本傳輸協定(HTTP)同步、非同步請求轉導問題。 In summary, the present invention provides a system and method for implementing a high-availability application program interface gateway under a microservice architecture based on message queues, which solves the problem of messages when the browser and the application program interface gateway are connected via WebSocket Synchronization issues, cross-domain WebSocket connection bridging issues, and cross-domain Hypertext Transfer Protocol (HTTP) synchronization and asynchronous request transduction issues.

請參照圖1,其是依據本發明之一實施例繪示的微服務系統示意圖。如圖1所示,微服務系統100包括部署於其中的一或多個API閘道器實例11~1N、訊息佇列120及微服務。在本發明的實施例中,一個API閘道器實例可對應於一或多個微服務。以API閘道器實例11為例,其可對應於一或多個微服務130。在一些實施例中,API閘道器實例11可用於協助將來自微服務130的訊息轉導至特定的使用者,其相關細節將在之後詳述。 Please refer to FIG. 1, which is a schematic diagram of a micro service system according to an embodiment of the present invention. As shown in FIG. 1, the microservice system 100 includes one or more API gateway instances 11-1N, a message queue 120, and microservices deployed therein. In the embodiment of the present invention, one API gateway instance may correspond to one or more microservices. Taking API gateway instance 11 as an example, it may correspond to one or more microservices 130. In some embodiments, the API gateway instance 11 can be used to help redirect the message from the microservice 130 to a specific user, and the relevant details will be detailed later.

在本發明的實施例中,各API閘道器實例的結構類似,故以下將暫以API閘道器實例11為例進行說明。如圖1所示,API閘道器實例11可包括請求處理模組111、訊息佇列模組112、註冊模組113、HTTP請求轉導模組114及Websocket模組115。概略而言,請求處理模組111係負責處理所有HTTP請求的收發,訊息佇列模組112可全時間聆聽訊息佇列120,負責收發訊息。請求處理模組111與訊息佇列模組112為API閘道器實例11的統一介面。對外,系統使用者可使用瀏覽器並透過HTTP請求觸及API閘道器實例11。對內,同個微服務系統100架構下之其他微服務則可透過HTTP請求與訊息佇列120與API閘道器實例11通訊。 In the embodiment of the present invention, the structure of each API gateway instance is similar, so the following will temporarily take API gateway instance 11 as an example for description. As shown in FIG. 1, the API gateway instance 11 may include a request processing module 111, a message queue module 112, a registration module 113, an HTTP request transduction module 114, and a Websocket module 115. Generally speaking, the request processing module 111 is responsible for processing all the sending and receiving of HTTP requests, and the message queue module 112 can listen to the message queue 120 at all times, and is responsible for sending and receiving messages. The request processing module 111 and the message queue module 112 are a unified interface of the API gateway instance 11. Externally, system users can use a browser and access API gateway instance 11 through HTTP requests. Internally, other microservices under the same microservice system 100 framework can communicate with the API gateway instance 11 through the HTTP request and message queue 120.

在一些實施例中,在使用者透過所使用的瀏覽器連線至以微服務架構部署高可用性API閘道器的微服務系統100後,每個瀏覽器請求將隨機與微服務系統100中的任一API閘道器實例連線。為便於說明,以下假設使用者的瀏覽器係連線至API閘道器實例11。在此情況下,請求處理模組111會先從使用者的瀏覽器收到HTTP連線請求,之後將據以與使用者的瀏覽器建立Websocket連線。同時,請求處理模組111還可依據HTTP連線請求呼叫註冊模組113。相應地,註冊模組113將根據HTTP連線請求中的使用者識別碼(userId)欄位組成註冊資訊,並暫存於API閘道器實例11的記憶體中,進而完成一次連線註冊動作。在一實施例中,API閘道器實例11的記憶體中可儲存有用於記錄註冊於API閘道器實例11上的各使用者的註冊資訊(例如包括使用者識 別碼),但本發明可不限於此。 In some embodiments, after the user connects to the microservice system 100 that deploys a high-availability API gateway with a microservice architecture through the browser they are using, each browser request will be randomly assigned to the microservice system 100 Any API gateway instance connection. For ease of explanation, the following assumes that the user's browser is connected to API gateway instance 11. In this case, the request processing module 111 first receives the HTTP connection request from the user's browser, and then establishes a Websocket connection with the user's browser accordingly. At the same time, the request processing module 111 can also call the registration module 113 according to the HTTP connection request. Correspondingly, the registration module 113 composes registration information according to the user ID (userId) field in the HTTP connection request, and temporarily stores it in the memory of the API gateway instance 11 to complete a connection registration action . In one embodiment, the memory of the API gateway instance 11 may store the registration information used to record each user registered on the API gateway instance 11 (for example, including user identification). Don't code), but the present invention is not limited to this.

之後,若微服務系統11中有某微服務需要發送訊息給連線至微服務系統100的特定使用者時,可採用以下的第一、第二實施例所提供的機制來進行。 After that, if there is a microservice in the microservice system 11 that needs to send a message to a specific user connected to the microservice system 100, the mechanism provided by the following first and second embodiments can be used to proceed.

在第一實施例中,假設微服務130欲發送訊息給某個使用者,則微服務130可在將此使用者的使用者識別碼作為接收者身分之後,將其與相關的訊息內容一併以HTTP請求(下稱第一HTTP請求)發送至對應於微服務130的API閘道器實例11。 In the first embodiment, assuming that the microservice 130 wants to send a message to a certain user, the microservice 130 can use the user ID of the user as the recipient identity, and then combine it with the related message content The HTTP request (hereinafter referred to as the first HTTP request) is sent to the API gateway instance 11 corresponding to the microservice 130.

在API閘道器實例11的請求處理模組111接收上述第一HTTP請求之後,可由註冊模組113確認API閘道器實例11(的記憶體)中是否儲存有對應於此使用者識別碼的註冊資訊。在一實施例中,若註冊模組113在API閘道器實例11中查到匹配於接收者身分的註冊資訊,即代表此使用者已向API閘道器實例11註冊,且此使用者的瀏覽器與API閘道器實例11之間已存在Websocket連線。因此,Websocket模組115即可透過前述Websocket連線將相關的訊息內容轉導至使用者所使用的瀏覽器。 After the request processing module 111 of the API gateway instance 11 receives the first HTTP request, the registration module 113 can confirm whether the API gateway instance 11 (memory) stores the corresponding user ID Registration information. In one embodiment, if the registration module 113 finds registration information matching the recipient's identity in the API gateway instance 11, it means that the user has registered with the API gateway instance 11, and the user’s There is already a Websocket connection between the browser and API gateway instance 11. Therefore, the Websocket module 115 can forward the relevant message content to the browser used by the user through the aforementioned Websocket connection.

在另一實施例中,若註冊模組113未能在API閘道器實例11中查到匹配於接收者身分的註冊資訊,即代表此使用者並未註冊於API閘道器實例11(即,尚未與API閘道器實例11建立Websocket連線)。在此情況下,訊息佇列模組112可將相關的訊息內容及接收者身分封裝為一封裝訊息,並發送至訊息佇列120中進行儲存。 In another embodiment, if the registration module 113 fails to find the registration information matching the recipient's identity in the API gateway instance 11, it means that the user is not registered in the API gateway instance 11 (ie , Websocket connection has not been established with API gateway instance 11). In this case, the message queue module 112 can encapsulate the related message content and recipient identity into a package message, and send it to the message queue 120 for storage.

在本發明的實施例中,訊息佇列120中可包括不同的主題,而各主題可視為是可用於儲存特定類型訊息的子佇列,但本發明可不限於此。在第一實施例中,訊息佇列120中可包括一「MessageSyncEvent」主題,其可用於儲存由API閘道器實例封裝而得的封裝訊息,但本發明可不限於此。 In the embodiment of the present invention, the message queue 120 may include different themes, and each theme can be regarded as a sub-queue that can be used to store a specific type of message, but the present invention is not limited to this. In the first embodiment, the message queue 120 may include a "MessageSyncEvent" subject, which can be used to store the packaged message packaged by the API gateway instance, but the invention is not limited to this.

在第二實施例中,在其餘各API閘道器實例中的訊息佇列模組偵測到「MessageSyncEvent」主題中出現新的封裝訊息之後,即可透過本發明提出的訊息轉導方法來進行後續處理。相似地,若有其他API閘道器實例將所封裝的訊息佇存至「MessageSyncEvent」主題,則佇列訊息模組112亦可在偵測到「MessageSyncEvent」主題中出現新的封裝訊息後,透過本發明提出的訊息轉導方法來進行後續處理,而其相關細節將在之後搭配圖2作進一步說明。 In the second embodiment, after the message queue module in each of the remaining API gateway instances detects that a new encapsulated message appears in the subject of "MessageSyncEvent", it can proceed through the message transduction method proposed by the present invention Follow-up processing. Similarly, if there are other API gateway instances that queue the encapsulated message to the "MessageSyncEvent" topic, the queue message module 112 can also detect the presence of a new encapsulated message in the "MessageSyncEvent" topic through The message transduction method proposed by the present invention performs subsequent processing, and the related details will be further described in conjunction with FIG. 2 later.

此外,在第二實施例中,假設微服務130欲發送訊息給某個使用者,則微服務130可自行將相關的訊息內容及此訊息的接收者身分封裝為一封裝訊息,並將此封裝訊息轉發至訊息佇列120。在第二實施例中,訊息佇列120中可包括一「ApiGwRequest」主題,其可用於儲存由微服務自行封裝而得的封裝訊息,但本發明可不限於此。 In addition, in the second embodiment, assuming that the microservice 130 wants to send a message to a certain user, the microservice 130 can encapsulate the related message content and the identity of the recipient of the message into an encapsulated message, and encapsulate the encapsulated message. The message is forwarded to the message queue 120. In the second embodiment, the message queue 120 can include an "ApiGwRequest" theme, which can be used to store the encapsulated message encapsulated by the microservice itself, but the invention is not limited to this.

之後,當各API閘道器實例中的訊息佇列模組(例如訊息佇列模組112)偵測到「ApiGwRequest」主題中出現新的封裝訊息之後,亦可透過本發明圖2提出的訊息轉導方法來進行後續 處理。 Later, when the message queue module in each API gateway instance (for example, the message queue module 112) detects that a new package message appears in the "ApiGwRequest" subject, the message presented in Figure 2 of the present invention can also be used Transduction method for follow-up deal with.

請參照圖2,其是依據本發明之一實施例繪示的訊息轉導方法。本實施例的方法可由圖1的API閘道器實例11執行,以下即搭配圖1的內容說明各步驟的細節。 Please refer to FIG. 2, which is a message transduction method according to an embodiment of the present invention. The method of this embodiment can be executed by the API gateway instance 11 in FIG. 1. The details of each step are described below in conjunction with the content of FIG. 1.

首先,在步驟S210中,佇列訊息模組112可偵測微服務系統100中訊息佇列120的特定主題中是否出現第一訊息。在本實施例中,前述特定主題可以是第一實施例中的「MessageSyncEvent」主題或是第二實施例中的「ApiGwRequest」主題,但本發明可不限於此。 First, in step S210, the queue message module 112 can detect whether the first message appears in a specific topic of the message queue 120 in the microservice system 100. In this embodiment, the aforementioned specific theme may be the "MessageSyncEvent" theme in the first embodiment or the "ApiGwRequest" theme in the second embodiment, but the invention is not limited to this.

假設特定主題為第一實施例中的「MessageSyncEvent」主題,則所考慮的第一訊息可以是其他API閘道器實例為所對應的微服務所產生的封裝訊息,其可封裝有第一訊息內容及第一接收者身分。另一方面,若上述特定主題為第二實施例中的「ApiGwRequest」主題,則所考慮的第一訊息則可以由某個微服務自行將第一訊息內容及第一接收者身分封裝而得。 Assuming that the specific theme is the "MessageSyncEvent" theme in the first embodiment, the first message under consideration can be an encapsulated message generated by other API gateway instances for the corresponding microservice, which can encapsulate the first message content And the identity of the first recipient. On the other hand, if the above-mentioned specific theme is the "ApiGwRequest" theme in the second embodiment, the considered first message can be obtained by encapsulating the content of the first message and the identity of the first recipient by a certain microservice.

之後,在步驟S220中,佇列訊息模組112可解封裝第一訊息以取得第一訊息內容及第一接收者身分。接著,在步驟S220中,註冊模組113可判斷對應於第一接收者身分的第一使用者是否已透過第一瀏覽器註冊於API閘道器實例11上。例如,註冊模組113可確認API閘道器實例11(的記憶體)中是否儲存有對應於第一接收者身分的使用者識別碼。若是,即代表第一使用者已向API閘道器實例11註冊,且第一使用者的瀏覽器(下稱第一瀏 覽器)與API閘道器實例11之間已存在Websocket連線(下稱第一Websocket連線)。因此,Websocket模組115可接著在步驟S240中透過API閘道器實例11與第一瀏覽器之間的第一Websocket通道將第一訊息內容轉導至第一瀏覽器。 Afterwards, in step S220, the queue message module 112 can decapsulate the first message to obtain the first message content and the first recipient identity. Then, in step S220, the registration module 113 can determine whether the first user corresponding to the first recipient identity has been registered on the API gateway instance 11 through the first browser. For example, the registration module 113 can confirm whether the user ID corresponding to the identity of the first recipient is stored in the API gateway instance 11 (in the memory). If yes, it means that the first user has registered with API gateway instance 11, and the browser of the first user (hereinafter referred to as the first browser) There is already a Websocket connection (hereinafter referred to as the first Websocket connection) between the API gateway instance 11 and the browser. Therefore, the Websocket module 115 can then forward the first message content to the first browser through the first Websocket channel between the API gateway instance 11 and the first browser in step S240.

相反地,若對應於第一接收者身分的第一使用者未透過第一瀏覽器註冊於API閘道器實例11上,即代表第一使用者並未註冊於API閘道器實例11(即,尚未與API閘道器實例11建立Websocket連線)。因此,Websocket模組115可執行步驟S250以忽略第一訊息。 Conversely, if the first user corresponding to the identity of the first recipient is not registered on API gateway instance 11 through the first browser, it means that the first user is not registered on API gateway instance 11 (ie , Websocket connection has not been established with API gateway instance 11). Therefore, the Websocket module 115 may perform step S250 to ignore the first message.

由上可知,在本發明的實施例中,當微服務欲發送訊息給特定的使用者,但此使用者未註冊於此微服務對應的API閘道器實例時,可由對應的API閘道器實例將相關的訊息內容及接收者身分封裝為封裝訊息(即,第一實施例的作法),或是由微服務自行將相關的訊息內容及接收者身分封裝為封裝訊息(即,第二實施例的作法)。之後,上述封裝訊息可被儲存至訊息佇列中的對應的特定主題,而各API閘道器實例可在偵測到特定主題中出現新的封裝訊息之後,可將其解封裝以取得其中的接收者身分。接著,若某API閘道器實例判定此接收者身分的使用者已註冊於自身上,則此API閘道器實例可透過已建立的Websocket連線將訊息內容予以轉導,反之則可予以忽略。 It can be seen from the above that, in the embodiment of the present invention, when a microservice wants to send a message to a specific user, but the user is not registered in the API gateway instance corresponding to the microservice, the corresponding API gateway can be used The example encapsulates the related message content and recipient identity as an encapsulated message (that is, the method of the first embodiment), or the microservice itself encapsulates the related message content and recipient identity as an encapsulated message (that is, the second embodiment) Example of practice). Afterwards, the above-mentioned encapsulated message can be stored in the corresponding specific topic in the message queue, and each API gateway instance can decapsulate it after detecting a new encapsulated message in the specific topic to obtain the content The identity of the recipient. Then, if an API gateway instance determines that the user of the receiver identity is registered on itself, the API gateway instance can relay the message content through the established Websocket connection, otherwise it can be ignored .

此外,在其他實施例中,本發明更提出在瀏覽器之間的同步/非同步轉導機制。具體而言,在一實施例中,假設一第二使 用者已透過第二瀏覽器註冊於API閘道器實例11,而API閘道器實例11已相應地與第二瀏覽器建立第二Websocket連線。在此情況下,第二瀏覽器可發送一第二HTTP請求至請求處理模組111,其中此HTTP請求可包括標頭欄位,而此標頭欄位可夾帶有目的位址與認證令牌(token)。 In addition, in other embodiments, the present invention further proposes a synchronous/asynchronous transduction mechanism between browsers. Specifically, in one embodiment, it is assumed that a second user The user has registered in the API gateway instance 11 through the second browser, and the API gateway instance 11 has established a second Websocket connection with the second browser accordingly. In this case, the second browser can send a second HTTP request to the request processing module 111, where the HTTP request can include a header field, and the header field can carry the destination address and the authentication token (token).

在非同步轉導機制中,在從第二瀏覽器接收上述第二HTTP請求之後,請求處理模組111可從標頭欄位解析出上述目的位址,並可由HTTP請求轉導模組114產生對應的唯一通用識別碼(UUID)。之後,HTTP請求轉導模組114可透過第二Websocket連線將上述唯一通用識別碼回傳至第二瀏覽器。接著,HTTP請求轉導模組114可基於目的位址透過執行緒呼叫對應的目的端。並且,反應於從目的端收到回應,執行緒可將此回應及上述唯一通用識別碼封裝為封裝訊息,並由Websocket模組115透過第二Websocket連線回傳至第二瀏覽器。 In the asynchronous transduction mechanism, after receiving the aforementioned second HTTP request from the second browser, the request processing module 111 can parse the aforementioned destination address from the header field, which can be generated by the HTTP request transduction module 114 The corresponding unique universal identification code (UUID). After that, the HTTP request transduction module 114 can return the above-mentioned unique universal identification code to the second browser through the second Websocket connection. Then, the HTTP request transduction module 114 can call the corresponding destination through a thread based on the destination address. And, in response to receiving a response from the destination, the thread can encapsulate the response and the above-mentioned unique universal identification code as an encapsulated message, and the Websocket module 115 sends it back to the second browser through the second Websocket connection.

在一實施例中,若第二瀏覽器意圖透過第二HTTP請求呼叫多個目的端,則HTTP請求轉導模組114可對各目的端指派專用的執行緒,而每個執行緒可用於呼叫一個目的端。並且,各執行緒在收到各自目的端的回應之後,可獨立地將回應及上述唯一通用識別碼封裝為封裝訊息,並由Websocket模組115透過第二Websocket連線回傳至第二瀏覽器。 In one embodiment, if the second browser intends to call multiple destinations through the second HTTP request, the HTTP request transduction module 114 can assign a dedicated thread to each destination, and each thread can be used for calling A destination. Moreover, after each thread receives the response from the respective destination, it can independently encapsulate the response and the above-mentioned unique universal identification code into an encapsulated message, which is sent back to the second browser by the Websocket module 115 through the second Websocket connection.

此外,在同步轉導機制中,在從第二瀏覽器接收上述第二HTTP請求之後,請求處理模組111可從標頭欄位解析出上述 目的位址。之後,HTTP請求轉導模組114可基於此目的位址同步地呼叫位於目的位址的多個特定微服務。之後,反應於從各特定微服務接收對應於上述第二HTTP請求的一特定回應,HTTP請求轉導模組114可將各特定微服務的特定回應合併為一JSON格式,並將此JSON格式回覆予第二瀏覽器。 In addition, in the synchronous transduction mechanism, after receiving the above-mentioned second HTTP request from the second browser, the request processing module 111 can parse the above-mentioned destination address from the header field. After that, the HTTP request transduction module 114 can synchronously call multiple specific microservices located at the destination address based on the destination address. Afterwards, in response to receiving a specific response corresponding to the above-mentioned second HTTP request from each specific microservice, the HTTP request transduction module 114 may merge the specific response of each specific microservice into a JSON format, and reply the JSON format I'm a second browser.

綜上所述,本發明可提供一種支援一個瀏覽器同時與多個WebSocket伺服端連線之方法以及提供一種在高可用性微服務架構下,支援同步與非同步的HTTP請求轉導機制。 In summary, the present invention can provide a method for supporting a browser to connect to multiple WebSocket servers at the same time and a mechanism for HTTP request transduction that supports synchronous and asynchronous under a high-availability microservice architecture.

透過RabbitMQ訊息佇列實作多個應用程式介面閘道器間的通訊機制,內含註冊模組以支援使用者識別,使用者於瀏覽器以帳號登入並與高可用性微服務架構下的任一應用程式介面閘道器連線後,該閘道器會根據使用者帳號產生使用者識別碼並儲存至記憶體,只要使用者以相同帳號登入,即便於不同瀏覽器也可同時收到訊息,也可做訊息轉導,經設定後以應用程式介面閘道器為入口同時訂閱多個位於不同網域下的WebSocket伺服器。 Through the RabbitMQ message queue, the communication mechanism between multiple application interface gateways is implemented, and the registration module is included to support user identification. The user logs in with an account in the browser and communicates with any one of the high-availability micro-service architectures. After the application program interface gateway is connected, the gateway will generate a user ID based on the user account and store it in the memory. As long as the user logs in with the same account, the message can be received at the same time even in different browsers. It can also be used for message transduction. After setting, use the application program interface gateway as the entrance to subscribe to multiple WebSocket servers located in different domains at the same time.

並且,本發明也支援瀏覽器之同步與非同步請求轉導,可依呼叫端發送之HTTP請求內的Header欄位中夾帶的目的網域,將該請求導向該網域,同步請求則直接同步呼叫,若為非同步請求則以WebSocket形式回傳至瀏覽器。此項技術特色可用於大型系統有多個內部子系統時,統一由對外的應用程式閘道器進行請求轉導,以避免子系統暴露於網際網路環境下造成資訊安全漏洞。當微服務架構部署多個應用程式閘道器實例時,由於呼叫 端每次呼叫的實例皆不同,本發明支援使用者識別與自動訊息同步,因此能正確將訊息同步至已和使用者瀏覽器建立連線的應用程式閘道器實例,由該實例轉導回使用者瀏覽器。 In addition, the present invention also supports the browser's synchronization and asynchronous request transduction. The request can be directed to the domain based on the destination domain contained in the Header field in the HTTP request sent by the caller, and the synchronization request is directly synchronized. If the call is an asynchronous request, it will be sent back to the browser in the form of WebSocket. This technical feature can be used when a large-scale system has multiple internal subsystems, and the external application gateway performs request transduction to prevent the subsystems from being exposed to the Internet environment and causing information security vulnerabilities. When the microservice architecture deploys multiple application gateway instances, due to the call The instance of each call is different. The present invention supports user identification and automatic message synchronization, so it can correctly synchronize the message to the instance of the application gateway that has established a connection with the user’s browser, and then forward it back User browser.

當大型系統只有一個對外接口時,本發明提供HTTP請求的同步與非同步轉導機制,統一由對外開放的應用程式閘道器將請求轉導至內部子系統,非同步請求則以WebSocket訊息回傳至使用者,以避免系統暴露造成資安漏洞。 When a large-scale system has only one external interface, the present invention provides a synchronous and asynchronous transduction mechanism for HTTP requests, and unified application gateways open to the outside world forward the requests to the internal subsystem, and asynchronous requests are returned by WebSocket messages. Pass it to users to avoid system exposure and information security loopholes.

雖然本發明已以實施例揭露如上,然其並非用以限定本發明,任何所屬技術領域中具有通常知識者,在不脫離本發明的精神和範圍內,當可作些許的更動與潤飾,故本發明的保護範圍當視後附的申請專利範圍所界定者為準。 Although the present invention has been disclosed in the above embodiments, it is not intended to limit the present invention. Anyone with ordinary knowledge in the relevant technical field can make some changes and modifications without departing from the spirit and scope of the present invention. The protection scope of the present invention shall be subject to those defined by the attached patent application scope.

S210~S250:步驟 S210~S250: steps

Claims (7)

一種訊息轉導方法,適於部署於一微服務系統中的一第一實例,其中該第一實例為一應用程式介面閘道器實例,包括:偵測該微服務系統中一訊息佇列的一特定主題中是否出現一第一訊息,其中該第一訊息係由該微服務系統中的一微服務封裝一第一訊息內容及一第一接收者身分而產生並轉發至該訊息佇列的該特定主題;解封裝該第一訊息以取得該第一訊息內容及該第一接收者身分;判斷對應於該第一接收者身分的一第一使用者是否已透過一第一瀏覽器註冊於該第一實例上;反應於判定該第一使用者已註冊於該第一實例上,透過與該第一瀏覽器之間的一第一Websocket連線將該第一訊息內容轉導至該第一瀏覽器。 A message transduction method is suitable for deploying in a first instance of a microservice system, wherein the first instance is an application programming interface gateway instance, including: detecting a message queue in the microservice system Whether a first message appears in a specific topic, where the first message is generated by a microservice in the microservice system encapsulating a first message content and a first recipient identity and forwarded to the message queue The specific subject; unpack the first message to obtain the content of the first message and the identity of the first recipient; determine whether a first user corresponding to the identity of the first recipient has been registered with a first browser On the first instance; in response to determining that the first user has been registered on the first instance, the content of the first message is transferred to the first instance through a first Websocket connection with the first browser A browser. 如申請專利範圍第1項所述的方法,更包括:反應於判定該第一使用者未註冊於該第一實例上,忽略該第一訊息。 For example, the method described in item 1 of the scope of patent application further includes: ignoring the first message in response to determining that the first user is not registered on the first instance. 如申請專利範圍第1項所述的方法,更包括:反應於一第二使用者透過一第二瀏覽器連接至該微服務系統,從該第二瀏覽器接收一瀏覽器請求,並據以與該第二瀏覽器建立一第二Websocket連線,其中該瀏覽器請求包括該第二使用者的一使用者識別; 基於該第二使用者的該使用者識別組成一註冊資訊,並儲存於該第一實例中。 For example, the method described in claim 1 further includes: responding to a second user connecting to the microservice system through a second browser, receiving a browser request from the second browser, and according to Establishing a second Websocket connection with the second browser, wherein the browser request includes a user identification of the second user; Based on the user identification of the second user, a piece of registration information is formed and stored in the first instance. 如申請專利範圍第3項所述的方法,其中該第一實例對應於一微服務,且該第一實例上註冊有至少一使用者,且所述方法更包括:從該微服務接收一第一超文本傳輸協定請求,其中該第一超文本傳輸協定請求包括一第二訊息內容及一第二接收者身分;判斷該第二接收者身分是否匹配於該至少一使用者的其中之一;反應於該第二接收者身分匹配於該至少一使用者中的該第二使用者的該註冊資訊,透過該第二Websocket連線將該第二訊息內容轉導至該第二瀏覽器;反應於該第二接收者身分未匹配於該至少一使用者中的任一,將該第二訊息內容及該第二接收者身分封裝為一第二訊息,並將該第二訊息轉發至該訊息佇列的該特定主題。 The method according to claim 3, wherein the first instance corresponds to a microservice, and at least one user is registered on the first instance, and the method further includes: receiving a second instance from the microservice A hypertext transfer protocol request, wherein the first hypertext transfer protocol request includes a second message content and a second recipient identity; determining whether the second recipient identity matches one of the at least one user; Responding to the registration information of the second user whose identity of the second recipient matches the at least one user, forwarding the content of the second message to the second browser through the second Websocket connection; When the second recipient identity does not match any of the at least one user, encapsulate the content of the second message and the second recipient identity into a second message, and forward the second message to the message The specific topic in the queue. 如申請專利範圍第3項所述的方法,更包括:從該第二瀏覽器接收一第二超文本傳輸協定請求,其中該第二超文本傳輸協定請求包括一標頭欄位,其夾帶有一目的位址與一認證令牌;從該標頭欄位解析出該目的位址,並產生對應的一唯一通用識別碼; 透過該第二Websocket連線將該唯一通用識別碼回傳至該第二瀏覽器;基於該目的位址透過一執行緒呼叫對應的一目的端;反應於從該目的端收到一回應,將該回應及該唯一通用識別碼封裝為一封裝訊息,並透過該第二Websocket連線回傳至該第二瀏覽器。 The method described in item 3 of the scope of patent application further includes: receiving a second hypertext transfer protocol request from the second browser, wherein the second hypertext transfer protocol request includes a header field with a The destination address and an authentication token; the destination address is parsed from the header field, and a corresponding unique universal identification code is generated; Return the unique universal identification code to the second browser through the second Websocket connection; call a corresponding destination through a thread based on the destination address; respond to receiving a response from the destination, send The response and the unique universal identification code are encapsulated as an encapsulated message and sent back to the second browser through the second Websocket connection. 如申請專利範圍第1項所述的方法,更包括:反應於從一第二瀏覽器接收一第二超文本傳輸協定請求,從該第二超文本傳輸協定訊息的一標頭欄位解析出一目的位址;基於該目的位址同步地呼叫位於該目的位址的多個特定微服務;反應於從各該特定微服務接收對應於該第二超文本傳輸協定請求的一特定回應,將各該特定微服務的該特定回應合併為一JSON格式,並將該JSON格式回覆予該第二瀏覽器。 For example, the method described in claim 1 further includes: in response to receiving a second hypertext transfer protocol request from a second browser, parsing from a header field of the second hypertext transfer protocol message A destination address; based on the destination address to synchronously call a plurality of specific microservices located at the destination address; in response to receiving a specific response from each of the specific microservices corresponding to the second hypertext transfer protocol request, the The specific response of each specific microservice is merged into a JSON format, and the JSON format is returned to the second browser. 一種應用程式介面閘道器,其部署於一微服務系統中,包括:一訊息佇列模組,其經配置以:偵測該微服務系統中一訊息佇列的一特定主題中是否出現一第一訊息,其中該第一訊息係由該微服務系統中的一微服務封裝一第一訊息內容及一第一接收者身分而產生並轉發至該訊息佇列的該特定主題; 解封裝該第一訊息以取得該第一訊息內容及該第一接收者身分;一註冊模組,其判斷對應於該第一接收者身分的一第一使用者是否已透過一第一瀏覽器註冊於該第一實例上;一Websocket模組,其在該註冊模組判定該第一使用者已註冊於該第一實例上後,透過與該第一瀏覽器之間的一第一Websocket連線將該第一訊息內容轉導至該第一瀏覽器。 An application programming interface gateway, which is deployed in a microservice system, includes: a message queue module, which is configured to: detect whether a specific subject of a message queue in the microservice system appears A first message, where the first message is generated by a microservice in the microservice system encapsulating a first message content and a first recipient identity and forwarded to the specific topic of the message queue; Decapsulate the first message to obtain the content of the first message and the identity of the first recipient; a registration module that determines whether a first user corresponding to the identity of the first recipient has passed through a first browser Registered on the first instance; a Websocket module, which after the registration module determines that the first user has been registered on the first instance, through a first Websocket connection with the first browser The line forwards the content of the first message to the first browser.
TW108130909A 2019-08-28 2019-08-28 Message redirecting method and application programming interface gateway TWI728445B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
TW108130909A TWI728445B (en) 2019-08-28 2019-08-28 Message redirecting method and application programming interface gateway

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
TW108130909A TWI728445B (en) 2019-08-28 2019-08-28 Message redirecting method and application programming interface gateway

Publications (2)

Publication Number Publication Date
TW202110139A TW202110139A (en) 2021-03-01
TWI728445B true TWI728445B (en) 2021-05-21

Family

ID=76035606

Family Applications (1)

Application Number Title Priority Date Filing Date
TW108130909A TWI728445B (en) 2019-08-28 2019-08-28 Message redirecting method and application programming interface gateway

Country Status (1)

Country Link
TW (1) TWI728445B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113111374B (en) * 2021-05-13 2022-09-23 上海交通大学 Industrial micro-service system of end edge cloud, data interaction method and medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170331802A1 (en) * 2016-05-11 2017-11-16 Oracle International Corporation Key Generation and Rollover
US20180013763A1 (en) * 2016-05-11 2018-01-11 Oracle International Corporation Multi-tenant identity and data security management cloud service

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170331802A1 (en) * 2016-05-11 2017-11-16 Oracle International Corporation Key Generation and Rollover
US20180013763A1 (en) * 2016-05-11 2018-01-11 Oracle International Corporation Multi-tenant identity and data security management cloud service

Also Published As

Publication number Publication date
TW202110139A (en) 2021-03-01

Similar Documents

Publication Publication Date Title
US7933272B2 (en) Methods and systems for resolving a first node identifier in a first identifier domain space to a second node identifier in a second identifier domain space
US8811572B2 (en) Systems and methods for exchanging call routing policies for voice over IP calls
TWI374646B (en) Apparatus for automated service discovery and dynamic connection management and system for the same
TW201815131A (en) Data transmission method and network equipment
US9680948B2 (en) System and method for device failure notification
WO2022100020A1 (en) Vulnerability testing method and apparatus
US20230031062A1 (en) Data processing method and apparatus, related device, and storage medium
TWI728445B (en) Message redirecting method and application programming interface gateway
CN108076007A (en) A kind of implementation method of interface, device and equipment
US20180295162A1 (en) Communications methods, apparatus and systems for correlating registrations, service requests and calls
JPWO2009110158A1 (en) Service control apparatus, service control system and method
US20170289318A1 (en) Implementing logical endpoints in internet-enabled devices
US20150358263A1 (en) Communication between a web application instance connected to a connection server and a calling entity other than said connection server
JP2006067592A (en) Method for routing messages between servers located on the same board
US11412370B2 (en) Method and system for low density hosted telephony regulatory compliance
JP6305786B2 (en) Incoming call control apparatus, incoming call control method, and program
TWI271968B (en) Network address translation router and related method
WO2019041332A1 (en) Method and system for optimizing transmission of acceleration network
US20230087220A1 (en) Data processing method and apparatus based on instant messaging, device, and storage medium
BRPI0800611B1 (en) method performed by a mobile communication device, mobile communication device, network communication device and media read by computer
EP3573309B1 (en) Network telephone processing method and related network device
WO2019210614A1 (en) Method and apparatus for implementing page function reuse
WO2014063612A1 (en) Method for smart end node to access to trill network, smart end node and routing bridge
US11804986B2 (en) Method for the remote management of a device connected to a residential gateway
GB2531398A (en) Communication system, Communication method, and transmission apparatus