CN116389556A - Service subscription method and device based on Dubbo framework - Google Patents

Service subscription method and device based on Dubbo framework Download PDF

Info

Publication number
CN116389556A
CN116389556A CN202310070728.0A CN202310070728A CN116389556A CN 116389556 A CN116389556 A CN 116389556A CN 202310070728 A CN202310070728 A CN 202310070728A CN 116389556 A CN116389556 A CN 116389556A
Authority
CN
China
Prior art keywords
service
application server
dubbo
sih
framework
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.)
Pending
Application number
CN202310070728.0A
Other languages
Chinese (zh)
Inventor
单德祥
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.)
Industrial and Commercial Bank of China Ltd ICBC
ICBC Technology Co Ltd
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
ICBC Technology 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 Industrial and Commercial Bank of China Ltd ICBC, ICBC Technology Co Ltd filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202310070728.0A priority Critical patent/CN116389556A/en
Publication of CN116389556A publication Critical patent/CN116389556A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Stored Programmes (AREA)

Abstract

The application provides a service subscription method and device based on a Dubbo framework, which can be used in the financial field or other technical fields. The method comprises the following steps: acquiring an IP address list of an application server pushed by a configuration center, wherein the IP address of the application server is maintained in the configuration center, and the application is constructed based on a non-Dubbo framework; registering virtual service to a registry according to the IP address list of the application server; subscribing to the virtual service. The device is used for executing the method. The service subscription method and the device based on the Dubbo framework realize communication between the service provider based on the non-Dubbo framework and the service caller based on the Dubbo framework.

Description

Service subscription method and device based on Dubbo framework
Technical Field
The application relates to the technical field of finance or other technologies, in particular to a service subscription method and device based on a Dubbo framework.
Background
Dubbo is a distributed service framework that aims to provide high performance and transparent RPC remote service invocation schemes, as well as SOA service governance schemes. Both the service provider and the service caller must rely on the Dubbo framework application today.
Disclosure of Invention
Aiming at the problems in the prior art, the embodiment of the application provides a service subscription method and device based on a Dubbo framework, which can at least partially solve the problems in the prior art.
In one aspect, an embodiment of the present application provides a service subscription method based on a Dubbo framework, including:
acquiring an IP address list of an application server pushed by a configuration center, wherein the IP address of the application server is maintained in the configuration center, and the application is constructed based on a non-Dubbo framework;
registering virtual service to a registry according to the IP address list of the application server;
subscribing to the virtual service.
In another aspect, an embodiment of the present application provides a service subscription apparatus based on a Dubbo framework, including:
the system comprises an acquisition module, a configuration center and a configuration module, wherein the acquisition module is used for acquiring an IP address list of an application server pushed by the configuration center, wherein the IP address of the application server is maintained in the configuration center, and the application is constructed based on a non-Dubbo framework;
the registration module is used for registering the virtual service to the registration center according to the IP address list of the application server;
and the subscription module is used for subscribing the virtual service.
The embodiment of the application also provides an electronic device, which comprises a memory, a processor and a computer program stored on the memory and capable of running on the processor, wherein the steps of the service subscription method based on the Dubbo framework described in any embodiment are realized when the processor executes the program.
The present application further provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the Dubbo framework based service subscription method described in any of the above embodiments.
In the service subscription method and device based on the Dubbo framework, taking the application OutboundAlder based on the Dubbo framework and the application SIH based on the non-Dubbo framework as examples, the SIH does not adopt a DSF framework, so that the service can not be registered with the service registry. The outboundup is essentially a consumer of DSF framework, and in order to be able to dock with the SIH system, a "virtual" DSF service is designed, having the outboundup stub out subscribe to and call it, enabling communication between the non-Dubbo framework based service provider and the Dubbo framework based service caller.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art. In the drawings:
fig. 1 is a schematic flow chart of a service subscription method based on the Dubbo framework according to an embodiment of the present application.
Fig. 2 is a schematic partial flow chart of a service subscription method based on the Dubbo framework according to an embodiment of the present application.
Fig. 3 is a schematic partial flow chart of a service subscription method based on the Dubbo framework according to an embodiment of the present application.
Fig. 4 is a schematic partial flow chart of a service subscription method based on the Dubbo framework according to an embodiment of the present application.
Fig. 5 is a schematic partial flow chart of a service subscription method based on the Dubbo framework according to an embodiment of the present application.
Fig. 6 is a schematic partial flow chart of a service subscription method based on the Dubbo framework according to an embodiment of the present application.
Fig. 7 is a schematic diagram of an overall application architecture of an OutboundAdapter according to an embodiment of the present application.
Fig. 8 is a schematic architecture diagram of a DFS framework according to an embodiment of the present application.
Fig. 9 is a flow chart of an encoding and decoding method based on the SIH TCP transmission protocol according to an embodiment of the present application.
Fig. 10 is a schematic structural diagram of a service subscription device based on the Dubbo framework according to an embodiment of the present application.
Fig. 11 is a schematic physical structure of an electronic device according to an embodiment of the present application.
Detailed Description
For the purposes of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the embodiments of the present application will be described in further detail with reference to the accompanying drawings. The illustrative embodiments of the present application and their description are presented herein to illustrate the application and not to limit the application. It should be noted that, in the case of no conflict, the embodiments and features in the embodiments may be arbitrarily ordered with each other.
The terms "first," "second," … …, and the like, as used herein, do not denote a particular order or sequence, nor are they intended to limit the application solely to distinguish one element or operation from another in the same technical terms.
As used herein, the terms "comprising," "including," "having," "containing," and the like are intended to be inclusive and mean an inclusion, but not limited to.
As used herein, "and/or" includes any or all ordering of such things.
For a better understanding of the present application, the following detailed description is given of the research background of the present application:
dubbo: distributed service frameworks, which are directed to providing high performance and transparent RPC remote service invocation schemes, and SOA service governance schemes.
DSF: the business bank provides functions of a registration center, a service gateway, monitoring management and the like for the service application based on the distributed service platform realized by Dubbo, so that service consumers can quickly find and use the service, and monitoring and management of a service calling process are realized.
For one Dubbo framework-based application (assuming application name OutboundAldapter), if communication with another non-Dubbo application (assuming application name SIH) via TCP protocol is required, and the following limiting factors exist for both parties of communication:
1. SIH is implemented using C++ without the Dubbo framework;
2. the communication protocol is a TCP protocol;
3. SIH is used as a service end, outboundAdapter is used as a service access party to access SIH, and a communication mode adopts synchronous response;
4. the client side periodically sends heartbeat data to the SIH;
in addition to the above-mentioned limiting factors, it is desirable to utilize the relatively mature and stable functions of the Dubbo framework such as relatively mature TCP connection creation, connection reconnection, heartbeat management, dynamic increase and decrease of services, etc., and the existing protocols of the Dubbo framework are not supported.
The application follows the SPI expansion mechanism of the Dubbo framework on the basis of the Dubbo framework, and a set of RPC protocols (assuming that the protocol names are SIH protocols) are customized. In the SIH protocol, the service Consumer role is implemented, and the application SIH implemented by the service Consumer Consumer and not the Dubbo framework communicates through the native TCP protocol.
The application main points mainly include:
1. defining virtual Dubbo services: because service discovery, service invocation, etc. of the Dubbo framework need to be performed based on services, and the SIH system does not have this set of service models of the Dubbo framework, it is necessary to have the convemer of the Dubbo subscribe to and invoke a virtual service, and the name of this service may be arbitrary;
2. extension registryfactor: the Dubbo framework subscribes to services from the service registry by default. As the address of the service changes, dubbo dynamically adjusts invoke to support the dynamic changes of the service provider. Since the SIH does not employ the Dubbo framework, it is impossible to register a service with a service registry. In order to support the characteristic of dynamic change of SIH, the RegistryFactory needs to be expanded, and a docking Apollo configuration center is used for realizing service discovery so as to support the Tcp Server for dynamically increasing and reducing SIH;
3. extension Protocol: the SihProtocol class and the SihInvoker class are realized by self definition, and the TCP data exchange protocol of SIH is docked;
4. extended Codec2: realizing Sihcode class and finishing the encoding and decoding of SIH protocol.
(1) The encode implementation: when transmitting a TCP connection initialization message, a heartbeat message and a service message to the SIH, encoding and transmitting according to SIH requirements;
(2) decode implementation: when receiving a response message from the SIH, decrypting and processing according to SIH requirements;
5. extension exchange: the method mainly aims at adapting to the heartbeat protocol of SIH, has more newly added codes, and specifically comprises the following classes:
(1) SihHeaaderExchange Channel class: the channel for managing Netty mainly comprises functions of sending information, receiving information, closing the channel and the like;
(2) SihHeaderexchange Client class: for encapsulating the SihHeaaderExchange channel;
(3) SihHeaaderExchange: SPI extension class used as exchange;
(4) SihHeartBuatTask: for sending heartbeat messages;
(5) ReconnectTimerTask: and triggering reconnection operation once the channel is closed or the channel receives no heartbeat return message.
The following describes the service subscription method and device based on the Dubbo framework in detail:
the execution subject of the service subscription method based on the Dubbo framework provided in the embodiments of the present application includes, but is not limited to, a computer.
Fig. 1 is a flow chart of a service subscription method based on a Dubbo framework provided in an embodiment of the present application, and as shown in fig. 1, the service subscription method based on the Dubbo framework provided in the embodiment of the present application includes:
s101, acquiring an IP address list of an application server pushed by a configuration center, wherein the IP address of the application server is maintained in the configuration center, and the application is constructed based on a non-Dubbo framework;
s102, registering virtual service to a registry according to the IP address list of the application server;
s103, subscribing to the virtual service.
Specifically, taking the above-described Dubbo framework-based application offbound dadapter and non-Dubbo framework-based application SIH as examples, since the DSF framework is not employed by the SIH, it is impossible to register a service with the service registry. The outboundup is essentially a consumer of DSF framework, and in order to be able to dock with the SIH system, a "virtual" DSF service is designed, having the outboundup stub out subscribe to and call it, enabling communication between the non-Dubbo framework based service provider and the Dubbo framework based service caller.
As shown in fig. 2, in some embodiments, the registering the virtual service with the registry according to the IP address list of the application server includes:
s1021, determining a uniform resource locator list of the virtual service according to the IP address list;
and S1022, registering the virtual service to a registration center according to the uniform resource locator list.
Specifically, a uniform resource locator list (URL) of the virtual service is determined according to an IP address list pushed by the configuration center, and then the virtual service is registered to the registry according to the virtual service URL.
As shown in fig. 3, in some embodiments, the method further comprises:
s104, acquiring a latest application server IP address list pushed by the configuration center;
s105, updating the unified resource locator list of the virtual service according to the latest IP address list.
Specifically, the configuration center subscribes to the IP address configuration of the Tcp Server, when the IP address changes, the configuration center pushes the changed IP address list, the receiving end updates the URL of the virtual service according to the latest IP address list, and then the DSF framework dynamically updates the invoke according to the change of the URL of the virtual service. The reference implementation logic is as follows:
1. maintaining an IP address list of the SIH Tcp Server at an Apollo configuration center, for example:
travelsky.adapter.connectAddress[0]=sih://10.221.157.180:80/com.gykj.adapter.client.sih.consumer.ConsumerServiceconnections=1;
2. the access terminal subscribes to an IP address list of the SIH Tcp Server from an Apollo configuration center;
3. after the SIH Tcp Server changes, maintaining an IP address list on an Apollo configuration center;
4. the Apollo configuration center pushes the changed IP address list to the extended SIH registration center;
5. monitoring an Apollo configuration center, and immediately updating a local IP address list cache once a new IP address list is received;
6. the extended SIH registry updates the URL list of the virtual service according to the IP address list;
7. dubbo updates the invoke corresponding to the virtual service according to the updated URL list.
As shown in fig. 4, in some embodiments, after subscribing to the virtual service, the method further comprises:
s106, acquiring a service request sent by an external Dubbo service;
and S107, the service request is sent to the application server.
Specifically, the external Dubbo service calls the access service of the outboundadcapter through the DSF framework; the access service takes a service request of an external Dubbo service and then sends the service request to the application server.
As shown in fig. 5, in some embodiments, the sending the service request to the application server includes:
s1061, constructing a request message according to the service request and a customized transmission protocol specification;
s1062, sending the request message to the application server.
Specifically, the SIH TCP request message is constructed according to the SIH TCP transmission protocol specification, and finally is sent to the SIH TCP Server through the TCP connection.
As shown in fig. 6, in some embodiments, after sending the service request to the application server, the method further comprises:
s108, acquiring a response message generated by the application server according to the request message;
s109, decoding the response message according to the self-defined transmission protocol specification to obtain service processing result data;
and S110, sending the service processing result data to the external Dubbo service.
Specifically, after transmitting the message encode to the back-end SIH service, a response is also received; and feeding back service processing result data obtained after decoding the received response message according to the customized transmission protocol specification to the external Dubbo service.
In some embodiments, the Dubbo framework-based application (e.g., application OutboundAlter) communicates with another non-Dubbo application (e.g., application SIH) via the TCP protocol, and the sending the request message to the application server includes: the request message is sent to the application server through TCP connection; the obtaining the response message generated by the application server according to the request message includes: and acquiring a response message sent by the application server through TCP connection, wherein the response message is generated by the application server according to the request message.
For a better understanding of the present application, the service subscription method based on the Dubbo framework provided in the present application is described below by using a specific embodiment. The complete technical scheme is as follows:
1. OutboundAldapter design
The overall application architecture of the outboundadAN_SNter is shown in fig. 7, and the internal structure of the outboundadAN_SNter illustrates:
when a client accesses the sie Tcp Server, the DSF framework itself has very flexible expansion capability (SPI mechanism of the Dubbo framework) considering that its function is very similar to that of a consumer of one DSF, so that a private communication protocol supporting sie and an Apollo-based service discovery protocol by SPI expansion are designed, and specific design schemes are described below.
OutboundAldapter call flow description:
1. the external Dubbo service calls the access service of the OutboundAlder through the DSF framework;
2. the access service takes the request message of the external Dubbo service and then forwards the message to the drop-out module (essentially a consumer of the DSF framework);
3. the receiving module calls a mock interface according to a standard DSF consumer call mode, the DSF framework sends a message encoding to SIH service at the back end and receives a response, and the whole call adopts a synchronous mode;
4. the access module is used as a consumer and subscribes to an Apollo registry to realize service discovery so as to support the connection of the Tcp Server to be dynamically increased and decreased.
OutboundAldapter is essentially a consumer of the DSF framework, designed to be able to dock SIH systems as follows:
1. designing a virtual DSF service, and subscribing and calling the virtual DSF service by the output terminal;
2. and expanding the DSF framework and adapting to the SIH protocol.
Extensions to the DSF framework are the core of the design. In general, the output needs to be in butt joint with the Apollo as a registration center, adapt to the sie message protocol and adapt to the sie heartbeat mechanism, and the architecture diagram is shown in fig. 8.
2. OutboundAldapter concrete implementation
1. Virtual Dubbo service
Since service discovery, service invocation, etc. of the Dubbo framework need to be performed based on the service, and the SIH system does not have this set of service models of the Dubbo framework, the connection-out end needs to subscribe to and invoke a virtual service, and the name of this service may be arbitrary.
A virtual service interface MockService is defined that acts as a stub in the Dubbo framework for services provided by the Sih TCP Server. Since the interface is used only as a service reference, no specific implementation class need be provided.
The MockService interface includes a mocksmethod defined as follows:
entering into the ginseng: object type request and int type message type.
And (3) ginseng: a collection of Map types;
2. extended RegistryFactory
The DSF framework subscribes to services from the service registry by default based on the Dubbo implementation. As the address of the service changes, dubbo dynamically adjusts invoke to support dynamic changes in the service provider.
Since the SIH does not employ the DSF framework, it is impossible to register a service with a service registry. To support the feature of dynamic changes in the SIH Tcp Server, it is necessary to extend the RegistryFactory and interface with the Apollo configuration center to implement service discovery to support dynamic increases and decreases in the Tcp Server.
The configuration center subscribes the IP address configuration of the Tcp Server, when the IP address changes, the configuration center pushes the changed IP address list, the receiving end updates the URL of the virtual service according to the latest IP address list, and then the DSF framework dynamically updates the invoke according to the change of the URL of the virtual service. The reference implementation logic is as follows:
(1) Maintaining an IP address list of the SIH Tcp Server at an Apollo configuration center, for example:
travelsky.adapter.connectAddress[0]=sih://10.221.157.180:80/com.gykj.adapter.client.sih.consumer.ConsumerServiceconnections=1;
(2) The access terminal subscribes to an IP address list of the SIH Tcp Server from an Apollo configuration center;
(3) After the SIH Tcp Server changes, maintaining an IP address list on an Apollo configuration center;
(4) The Apollo configuration center pushes the changed IP address list to the extended SIH registration center;
(5) Monitoring an Apollo configuration center, and immediately updating a local IP address list cache once a new IP address list is received;
(6) The extended SIH registry updates the URL list of the virtual service according to the IP address list;
(7) Dubbo updates the invoke corresponding to the virtual service according to the updated URL list.
The extended registryfactor mainly includes the following classes:
(1) SihRegistry class
1) The SihRegulation class inherits the FailbackRegulation class.
2) The method mainly uses ApolloClient to obtain an SIH TCP Server list from an Apollo configuration center, and monitors the change condition of the SIH TCP Server list;
3) When the SIH TCP Server list changes, the URL list of the virtual service is dynamically updated.
4) Dubbo updates the invoke corresponding to the virtual service according to the updated URL list to achieve dynamic changes of the service provider.
(2) SihRegistryFactory class
1) The SihRegistryFactoy class is self-defined and inherits the Abstract RegistryFactoy class.
2) The class is taken as a SihRegulation factory class and is mainly used for creating and returning SihRegulation objects according to URLs.
(3) SpringBootApolloRefreshConfig class
And (3) adding a SpringBootApolloRefreshConfig as an Apollo monitoring event, and immediately updating the local cache of the IP address list once the IP address list of the SIH Tcp Server pushed by the Apollo is monitored.
3. Extension invoke
The SihInvker class is customized, inherits com.alibaba.dubbo.rpc.protocol.AbstraactInver class, and realizes a construction method and a rewriting doInvoke method.
The SihInvoker makes the SihProtocol have the role of Consumer, namely, the SihProtocol serves as a client to send a connection initialization message, a heartbeat message and a service message to the SIH TCP Server and receive a returned processing result.
(1) Construction method functional description:
1) Calling a construction method of the parent class;
2) The SIH system performs identity division on the nodes (essentially, the opposite ends of each TCP connection) interacted with the SIH system, one is to actively transmit transactions to the SIH system and receive the corresponding requests, and the other is to passively receive requests of the SIH system and return results, so that transactions cannot be actively transmitted. To support this feature, a special process needs to be performed in the sihvrank class, that is, in the constructor, for each TCP link, an identity message is sent to the SIH system, and after waiting for the SIH system to return an acknowledgement message, the invoker is set to be available.
(2) doInvoke method function description:
1) Constructing an RpcInvitation object;
2) Selecting an available exchange client from the exchange client array according to a load balancing strategy;
3) Sending TCP requests using exchange client
4) And receiving a returned result.
4. Expanding exporters
Since the SihProtocol does not need to implement the Provider role, the Exporter interface is not extended.
5. Extension Protocol
The custom SihProtocol inherits com.alibaba.dubbo.rpc.protocol.Abstract protocol, rewrites reference method, rewrites export method and realizes getClients method.
(1) reference method functional description:
and creating a SihInvoker object according to the input interface type and the URL, and adding the SihInvoker object into an invoker cache.
(2) export method functional description:
as only serves as a service consumer and does not need to realize the call of local specific service, null is directly returned;
(3) getClients method functional description:
1) Acquiring the connection number of SIH TCP virtual service from a configuration center;
2) According to the connection number, sequentially creating exchange client objects, and creating TCP connection with SIH TCPServer;
3) The created exchange client object is stored in an array for use by the SihInvoker.
6. Extended Codec2
The SIH TCP transport protocol format is as follows:
4bytes 1byte 4bytes content
magic cmd length content
(1) magic: field length 4byte (32 bits) for protocol discrimination
Figure BDA0004064730110000101
Fixed value: SIHX
(2) cmd: the field length is 1byte (8 bits) to indicate the message type. Wherein, 0xA access authentication correlation, 0xB heartbeat correlation, 0x3 traffic message.
Figure BDA0004064730110000102
0xA0, accessing SIH request message, initiated by client
Figure BDA0004064730110000103
0xA1 response message corresponding to access SIH access request
Figure BDA0004064730110000104
0xB0 heartbeat request initiated by client
Figure BDA0004064730110000105
0xB1: heart beat response, reply by SIH
Figure BDA0004064730110000111
0x31: synchronization request
Figure BDA0004064730110000112
0x32: asynchronous request
Figure BDA0004064730110000113
0x33: synchronous acknowledgement
Figure BDA0004064730110000114
0x34: reservation of
Figure BDA0004064730110000115
0x35 asynchronous acknowledgement
Figure BDA0004064730110000116
0x36 unidirectional message
Figure BDA0004064730110000117
0x37 reservation
Figure BDA0004064730110000118
0x38 reservation of
Figure BDA0004064730110000119
0x39 reservation of
(3) length: a field length of 4 bytes (32 bits) for indicating the length of the entire message
Figure BDA00040647301100001110
Message length, 4byte, max support 2147483647 (about 1.9G), should not exceed 512K when used
Figure BDA00040647301100001111
length=header length+content length
(4) content: the content of the message part is different according to the different cmd
In order to achieve communication with the SIH TCP Server, parsing of the SIH TCP transport protocol format needs to be achieved in the Dubbo framework.
As shown in FIG. 9, the Sihcodec class is customized to implement the encoding and decoding methods in the com.
(1) Method of encoding
The encode method functional description:
1) Firstly, when a message is sent to an SIH, an access message, a heartbeat message and a service message need to be encoded according to SIH requirements.
2) And finally, packaging and sending the message.
The encode method processing logic is as follows:
since the access Request message, the heartbeat Request message and the service response message are all encapsulated into a Request type, the processing logic is as follows:
Figure BDA00040647301100001112
first, the message content is read from the Request object.
Figure BDA00040647301100001113
Then, the SIH TCP request message is constructed according to the SIH TCP transport protocol format.
Figure BDA00040647301100001114
And finally, sending the message to the SIH TCP Server through a TCP connection.
(2) decoding method
decode method functional description:
1) Firstly, a message is received from an SIH, unpacking is carried out, and the problem of sticking is solved.
2) And then, distinguishing the service request message or the access and heartbeat response message according to the message content.
3) And finally, converting the service message response, the access response and the heartbeat response into response objects for processing. The decode method processing logic is as follows:
1) First, a maximum of 4 bytes of content is read from buffer, and it is sequentially determined whether each character is a SIHX. 2) If the message is not the first message of the SIHX, the message is an illegal message. If the unread message exists at the moment, the rest message is read.
Figure BDA0004064730110000121
Judging whether the read message has the following conditions: the substring SIHX, the last bit is S, the last two bits are SI, the last three bits are SIH, and the last four bits are SIHX.
Figure BDA0004064730110000122
If the condition does not exist, the read message is an illegal message, and is not processed,
directly skip and then return null.
Figure BDA0004064730110000123
If the situation exists, the character string from the message head to the position where the sub character string appears is an illegal message, and the process is not performed, and the process is directly skipped. The readerIndex of buffer is set to the position where the substring occurs so that the next cycle continues processing.
3) If the message is at the beginning of S, SI, SIH or SIHX, judging whether the readable message length is less than 9.
Figure BDA0004064730110000124
If the readable message Length is less than or equal to 9, the read SIH message content does not contain 1byte CMD and 4 bytes Length, and the subsequent message content NEEDs to be continuously read, and then the NEED_MORE_INPUT is directly returned.
Figure BDA0004064730110000125
If the readable message length is more than 9, the read SIH message content already contains 1byte CMD and 4 bytes length, unpacking is started, the message is normally analyzed, and the subsequent processing is continued.
4) Judging whether the readable message length readable in the buffer is larger than or equal to the content length indicated by length in the SIH message.
Figure BDA0004064730110000126
If the readable is smaller than length, which indicates that only part of SIH message is read and the subsequent SIH message content NEEDs to be read continuously, the NEED_MORE_INPUT is returned directly.
Figure BDA0004064730110000127
If the readable is greater than or equal to length, reading the content of the message with length of length, and continuing the subsequent processing.
And judging whether the content of the service is 0x0A finally according to the content read at the time.
Figure BDA0004064730110000131
If the content is not 0x0A, whether the content in the content has SHIX or not needs to be analyzed, and if so, the request which is invalid is directly returned to null.
Figure BDA0004064730110000132
If it is 0xAnd 0A, proving that no message is lost, and continuing the subsequent processing when the message is normal.
Figure BDA0004064730110000133
Finally, the requestId is fetched from the cache and the Response object is constructed and then returned.
7. Expansion exchange
The extended exchange related class is mainly used for adapting to the heartbeat protocol of the SIH, and mainly comprises the following classes:
(1) SihHeaaderExchange Channel class
1) And customizing the SihHeadstochangeChannel class to realize an exchange Channel interface.
2) The channel management system is mainly used for managing channel channels of Netty, and has the functions of sending heartbeat messages, receiving heartbeat messages, closing channels and the like by using the channel channels.
(2) SihHeaderexchange Client class
1) And customizing the SihHeaaderExchange client class to realize an exchange client interface.
2) The SihHeadstochangeChannel is encapsulated in a build process.
3) The method for rewriting the connection is added with the function of sending initialization connection information to the SIH TCP Server after the connection is established.
4) And a startheatbeattmer method and a stopstartbeattmer method are realized, and a heartbeat timing task is started or closed.
5) And a startreconnecttmer method and a stopreconnecttmer method are realized, and reconnection timing tasks are started or closed.
(3) SihHeaderexchange class
1) And customizing the SihHeaaderexchange class, and realizing an exchange interface as an SPI extension class of the exchange.
2) The connect method is rewritten, and a SihHeadErexchange client object is created and returned.
3) And (5) rewriting the bind method, and creating and returning the HeaderExchange Server object.
(4) SihHeartBuatTask class
1) The SihHeartBuatTask class is self-defined, a Runneable interface is realized, and the Runneable interface is used as an SPI extension class of an exchange.
2) The method of rewriting run is used for sending heartbeat messages.
(5) ReconnecttimerTask class
1) And the ReconnectTimerTask class is customized, a Runneable interface is realized, and the Runneable interface is used as an SPI extension class of an exchange.
2) And (3) rewriting the run method, and triggering reconnection operation once the channel is closed or the channel receives no heartbeat return message.
8. Connection creation
Tcp Server specification for SIH:
(1) SIH Tcp Server is used as Server, all calling party are used as client;
(2) For each SIH Tcp Server, there is a limit to the maximum number of connections allowed;
(3) The client is connected with the SIH Tcp Server in a long way;
(4) The client periodically sends heartbeat data to the SIH Tcp Server, and if the SIH Tcp Server does not receive the heartbeat data sent by the client in 3 continuous periods, the client is considered to be off-line, and the SIH Tcp Server actively closes the connection; if the client side does not receive heartbeat feedback data sent by the SIH Tcp Server for 3 continuous periods, the client side considers that the connection is not available, and actively closes the connection and recreates a new connection;
(5) SIH provides IP address of TCPServer cluster, and adaptation layer needs to realize load balancing strategy;
(6) Aiming at the IP address of the TCPServer cluster provided by SIH, the adaptation layer needs to support dynamic expansion, namely, under the condition that the adaptation layer does not need to be restarted, the corresponding TCP connection is dynamically added or deleted according to the IP address change of the TCPServer cluster;
for the technical specifications, the following way is adopted for realizing the outboundadAN_SNter at the output end:
(1) SihHeaderexchange Client is TcpClient defined in Dubbo expansion protocol SihProtocol;
(2) Creating a plurality of TcpCliens in SihProtecol, wherein each TcpClient maintains 1 TCP long connection, and the maximum number of connections allowed by TcpServer cannot be exceeded at most;
(3) The service thread pool of the SihHeaderExchange client uses a custom shared thread pool. N SihHeaaderExchange clients share a thread pool;
(4) After the creation of the TcpClient long connection is completed, the construction of the Dubbo invoke is started, an initialization message is required to be sent through the TcpClient in the construction process, and after the TcpServer returns a confirmation message, the TcpClient is calculated as successful in the creation.
(5) One invoke corresponds to one tcps erver. One invoke contains multiple sihheaderexchange clients.
(6) For a plurality of TcpServer, sihProtocol, supporting a load balancing strategy, wherein the load balancing strategy comprises random call load balancing, polling call load balancing and least active number call load balancing;
(7) For a plurality of SihHeaaderExchange clients of each TcpServer, supporting a polling call load balancing strategy;
(8) Providing virtual service MockService for the access service of the OutboundAldapter, sending SIH (service-specific information) messages to the TcpServer by a MockService mocksmethod, and sending load balancing strategy references 6 and 7;
(9) By expanding the SihRegistryFacto registry and detecting the change of the TcpServer in the apollo configuration center in a polling mode, the Invoker can be dynamically added or deleted.
(10) In the application starting process, a connection with the Tcp Server is created according to the configuration of the Tcp Server in the Apollo.
9. Connection checking and reconnection
When the TCP connection is idle (i.e. no service message is sent in a designated time interval, the default time interval is 3 seconds), the client periodically sends heartbeat data to the SIH Tcp Server. If the SIH Tcp Server does not receive heartbeat data sent by the client for 3 continuous periods, the client is considered to be off-line, and the SIH Tcp Server actively closes the connection; if the client does not receive heartbeat feedback data sent by the SIH Tcp Server for 3 continuous periods, the connection is considered to be unavailable, and the client actively closes the connection and recreates a new connection.
According to the SIH TCP transmission protocol, a timing task is set, a heartbeat request 0xB0 is sent periodically, and a reply 0xB1 of the SIH Tcp Server is received.
If a heartbeat return message cannot be received, a reconnection is required. And setting a reconnection task, and reconnecting after the heartbeat return message cannot be received in three heartbeat periods.
The technical scheme provided by the embodiment realizes that in the Dubbo framework, a new Dubbo protocol is customized by adopting an SPI mechanism of the Dubbo framework, the protocol can realize that the Dubbo application calls services of non-Dubbo application through a TCP protocol, and the conversion breaks through some limitations of the Dubbo framework in the prior art, such as only supporting JAVA language; both the service provider and the service caller rely on the Dubbo framework; the interface between the service provider and the service caller is strongly dependent, and the like, so that technical reference is provided for special scenes of some Dubbo applications, and the related scenes mainly comprise:
1. the client system does not use Java;
2. the client system does not employ the Dubbo framework;
3. the client system communication protocol is the TCP protocol.
Fig. 10 is a schematic structural diagram of a service subscription device based on a Dubbo framework according to an embodiment of the present application, as shown in fig. 10, where the service subscription device based on a Dubbo framework according to the embodiment of the present application includes:
an obtaining module 21, configured to obtain an IP address list of an application server pushed by a configuration center, where an IP address of the application server is maintained in the configuration center, and the application is built based on a non-Dubbo framework;
a registration module 22, configured to register a virtual service with a registry according to the IP address list of the application server;
a subscription module 23, configured to subscribe to the virtual service.
In the service subscription device based on the Dubbo framework provided in the embodiment of the present application, for example, an application outbounddadapter based on the Dubbo framework and an application SIH based on a non-Dubbo framework, since the SIH does not adopt a DSF framework, the service cannot be registered with the service registry. The outboundup is essentially a consumer of DSF framework, and in order to be able to dock with the SIH system, a "virtual" DSF service is designed, having the outboundup stub out subscribe to and call it, enabling communication between the non-Dubbo framework based service provider and the Dubbo framework based service caller.
In some embodiments, the registration module is specifically configured to:
determining a uniform resource locator list of the virtual service according to the IP address list;
and registering the virtual service to a registry according to the uniform resource locator list.
In some embodiments, the acquisition module is further to: acquiring the latest IP address list of the application server pushed by the configuration center;
the apparatus further comprises: and the updating module is used for updating the unified resource locator list of the virtual service according to the latest IP address list.
In some embodiments, the acquiring module is further configured to acquire a service request sent by the external Dubbo service;
the apparatus further comprises: and the sending module is used for sending the service request to the application server.
In some embodiments, the sending module is specifically configured to:
constructing a request message according to the service request and a customized transmission protocol specification;
and sending the request message to the application server.
In some embodiments, the obtaining module is further configured to obtain a response message generated by the application server according to the request message;
the apparatus further comprises: the decoding module is used for decoding the response message according to the self-defined transmission protocol specification to obtain service processing result data;
the sending module is further configured to: and sending the service processing result data to the external Dubbo service.
In some embodiments, the sending module sending the request message to the application server includes:
the request message is sent to the application server through TCP connection;
the obtaining module obtains a response message generated by the application server according to the request message, including:
and acquiring a response message sent by the application server through TCP connection, wherein the response message is generated by the application server according to the request message.
The embodiments of the apparatus provided in the embodiments of the present application may be specifically used to execute the processing flows of the embodiments of the above methods, and the functions thereof are not described herein again, and may refer to the detailed descriptions of the embodiments of the above methods.
It should be noted that, the service subscription method and device based on the Dubbo framework provided in the embodiments of the present application may be used in the financial field, and may also be used in any technical field other than the financial field, and the application field of the service subscription method and device based on the Dubbo framework is not limited in the embodiments of the present application.
Fig. 11 is a schematic physical structure of an electronic device according to an embodiment of the present application, as shown in fig. 11, the electronic device may include: processor 301, communication interface (Communications Interface) 302, memory (memory) 303 and communication bus 304, wherein processor 301, communication interface 302, memory 303 accomplish the communication between each other through communication bus 304. The processor 301 may invoke logic instructions in the memory 303 to perform the method described in any of the embodiments above.
Further, the logic instructions in the memory 303 may be implemented in the form of software functional units and stored in a computer readable storage medium when sold or used as a stand alone product. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The present embodiments disclose a computer program product comprising a computer program stored on a non-transitory computer readable storage medium, the computer program comprising program instructions which, when executed by a computer, are capable of performing the methods provided by the method embodiments described above.
The present embodiment provides a computer-readable storage medium storing a computer program that causes the computer to execute the methods provided by the above-described method embodiments.
It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In the description of the present specification, reference to the terms "one embodiment," "one particular embodiment," "some embodiments," "for example," "an example," "a particular example," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present application. In this specification, schematic representations of the above terms do not necessarily refer to the same embodiments or examples. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
The foregoing embodiments have been provided for the purpose of illustrating the general principles of the present application and are not meant to limit the scope of the invention, but to limit the scope of the invention.

Claims (10)

1. A method for subscribing to services based on a Dubbo framework, comprising:
acquiring an IP address list of an application server pushed by a configuration center, wherein the IP address of the application server is maintained in the configuration center, and the application is constructed based on a non-Dubbo framework;
registering virtual service to a registry according to the IP address list of the application server;
subscribing to the virtual service.
2. The method of claim 1, wherein registering the virtual service with the registry based on the list of IP addresses of the application server comprises:
determining a uniform resource locator list of the virtual service according to the IP address list;
and registering the virtual service to a registry according to the uniform resource locator list.
3. The method according to claim 2, wherein the method further comprises:
acquiring the latest IP address list of the application server pushed by the configuration center;
and updating the unified resource locator list of the virtual service according to the latest IP address list.
4. The method of claim 1, wherein after subscribing to the virtual service, the method further comprises:
acquiring a service request sent by an external Dubbo service;
and sending the service request to the application server.
5. The method of claim 4, wherein the sending the service request to the application server comprises:
constructing a request message according to the service request and a customized transmission protocol specification;
and sending the request message to the application server.
6. The method of claim 5, wherein after sending the service request to the application server, the method further comprises:
acquiring a response message generated by the application server according to the request message;
decoding the response message according to the customized transmission protocol specification to obtain service processing result data;
and sending the service processing result data to the external Dubbo service.
7. The method of claim 6, wherein the sending the request message to the application server comprises:
the request message is sent to the application server through TCP connection;
the obtaining the response message generated by the application server according to the request message includes:
and acquiring a response message sent by the application server through TCP connection, wherein the response message is generated by the application server according to the request message.
8. A Dubbo framework-based service subscription apparatus, comprising:
the system comprises an acquisition module, a configuration center and a configuration module, wherein the acquisition module is used for acquiring an IP address list of an application server pushed by the configuration center, wherein the IP address of the application server is maintained in the configuration center, and the application is constructed based on a non-Dubbo framework;
the registration module is used for registering the virtual service to the registration center according to the IP address list of the application server;
and the subscription module is used for subscribing the virtual service.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the method of any one of claims 1 to 7 when the computer program is executed by the processor.
10. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method according to any one of claims 1 to 7.
CN202310070728.0A 2023-01-13 2023-01-13 Service subscription method and device based on Dubbo framework Pending CN116389556A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310070728.0A CN116389556A (en) 2023-01-13 2023-01-13 Service subscription method and device based on Dubbo framework

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310070728.0A CN116389556A (en) 2023-01-13 2023-01-13 Service subscription method and device based on Dubbo framework

Publications (1)

Publication Number Publication Date
CN116389556A true CN116389556A (en) 2023-07-04

Family

ID=86977684

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310070728.0A Pending CN116389556A (en) 2023-01-13 2023-01-13 Service subscription method and device based on Dubbo framework

Country Status (1)

Country Link
CN (1) CN116389556A (en)

Similar Documents

Publication Publication Date Title
EP1924046B1 (en) A system, method and device for negotiating the equipment information
CN109756559B (en) Construction and use method for distributed data distribution service of embedded airborne system
US5892946A (en) System and method for multi-site distributed object management environment
US20020147652A1 (en) System and method for distruibuted client state management across a plurality of server computers
US20020073158A1 (en) Method and system for general-purpose interactive notifications
CN101188625B (en) Method and system for realizing information content subscription
JP2020537449A (en) Service registration in communication network
EP1584172A1 (en) Message transfer using multiplexed connections in an osi-tp environment
US20040243668A1 (en) Application programming interface for implementing directory service access using directory service markup language
EP1390861A2 (en) Service provision system and method
JP4205323B2 (en) Distribution system, distribution server and distribution method, distribution program
CN101673217B (en) Method for realizing remote program call and system thereof
CN105959349A (en) Distributed service end operation system and method
CN106679095A (en) Internet access method and device and intelligent air conditioner system
CN112422497A (en) Message transmission method and device and computer equipment
JP2002269061A (en) Client server system, repeating server, and method for determining connection destination server
CN115883633A (en) Dubbo frame-based request processing method and device
JP2003141002A (en) Url length conversion system and program
CN116389556A (en) Service subscription method and device based on Dubbo framework
CN107819831B (en) Metaq and mns-based universal message system
CN112799849B (en) Data processing method, device, equipment and storage medium
CN113973135A (en) Data caching processing method and device, caching grid platform and storage medium
CN114257576A (en) RPC server implementation method based on support of multiple communication protocols
CN111083182B (en) Distributed Internet of things equipment management method and device
US20040181530A1 (en) Distributed networking system for resource-constrained computing devices

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination