Disclosure of Invention
The invention provides a service bus communication method, electronic equipment and a computer storage medium, which are used for establishing different service items at the same service bus address and improving the communication quality of the service bus.
In order to solve the above technical problems, a first technical solution provided by the present invention is: a service bus communication method is provided, including: calling an online service interface by using a first task, and judging whether the service bus is monitored or not; if the service bus is not snooped, snooping the service bus using the first task; receiving, with the first task, a registration request of a second task for the service bus; registering the second task to the service bus in response to the registration request with the first task.
Wherein, the service bus communication method further comprises: receiving a connection request for the second task initiated by an external task by utilizing the first task; completing negotiation by using the first task and the second task to obtain a connection redirection result, wherein the connection redirection result comprises a dynamic service bus address of the second task; and sending the connection redirection result to the external task by utilizing the first task.
Wherein, the service bus communication method further comprises: establishing a point-to-point connection with the external task based on the dynamic service bus address using the second task.
Wherein the step of establishing a point-to-point connection with the external task based on the dynamic service bus address using the second task specifically comprises: receiving, by the second task, a connection request initiated by the external task based on the dynamic service bus address; and authenticating the connection request by using the second task, and establishing point-to-point connection with the external task based on the dynamic service bus address after the authentication is passed.
Wherein, the negotiating with the first task and the second task, and obtaining a connection redirection result includes: analyzing a service path of the external task by using the first task, and sending a connection request to the registered second task by using the first task based on the service path; and negotiating with the agent of the second task by using the registered second task to obtain the connection redirection result.
The calling an online service interface by using the first task and judging whether the service bus is monitored further comprises: if the service bus is monitored, sending a registration request for the service bus to a task monitoring the service bus by using the first task; after receiving a response to a task listening to the service bus, registering the first task with the service bus.
Wherein, the service bus communication method further comprises: judging whether the connection between the first task and the second task is disconnected or not by using the second task; and if the bus is disconnected, monitoring the service bus by using the second task.
Wherein, the service bus communication method further comprises: receiving a registration request of the restarted first task to the service bus by utilizing the second task; and utilizing the second task to respond to the registration request to register the restarted first task to the service bus.
In order to solve the above technical problems, a second technical solution provided by the present invention is: provided is an electronic device including: a memory storing program instructions and a processor retrieving the program instructions from the memory to perform any of the methods described above.
In order to solve the above technical problems, a third technical solution provided by the present invention is: there is provided a computer readable storage medium storing a program file executable to implement the method of any of the above.
The invention has the beneficial effects that the invention is different from the prior art, the invention uses the first task to call the online service interface and judges whether the service bus is monitored; if the service bus is not snooped, snooping the service bus using the first task; receiving, with the first task, a registration request of a second task for the service bus; registering the second task to the service bus in response to the registration request with the first task. Therefore, different service items are established at the same service bus address, and the communication quality of the service bus is improved.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first", "second" and "third" in this application are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implying any indication of the number of technical features indicated. Thus, a feature defined as "first," "second," or "third" may explicitly or implicitly include at least one of the feature. In the description of the present application, "plurality" means at least two, e.g., two, three, etc., unless explicitly specifically limited otherwise. All directional indications (such as up, down, left, right, front, and rear … …) in the embodiments of the present application are only used to explain the relative positional relationship between the components, the movement, and the like in a specific posture (as shown in the drawings), and if the specific posture is changed, the directional indication is changed accordingly. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
The prior art provides a method, system and device for implementing internet protocol connectivity on a service-oriented architecture bus implemented for peer-to-peer networks. At a first device, a first IP service is advertised on the SOA bus, and a second IP service advertised by a second device on the SOA bus is discovered. The first device may send at least the first IP packet to the second device by remotely invoking a second IP service of the second device over the SOA bus. The first device may receive at least a second IP packet from the second device over the SOA bus through a call to the first IP service by the second device. The disadvantage of this technique is that the bus service must be on-line all the time, and cannot be automatically replaced by other sub-services due to the bus service exception.
The prior art provides a service publishing method and a service publishing system, wherein the service publishing method includes: receiving a configuration instruction, and configuring service configuration information; determining request message parameter information and a response data structure according to the configured service configuration information; filling the request message parameter information and the response data structure into an ESB service protocol template so as to generate a service engineering package according to the ESB service protocol template; and issuing the service according to the service engineering package. Through the technical scheme of the invention, the service release can be effectively and directly carried out. The technology has the defect that the problem that the bus exception cannot be automatically recovered exists in the same way that the protocol dynamic issuing service is only solved.
The application provides a service bus communication method, different service items are established at the same service bus address, after the main service is abnormal, other services automatically recover the bus, and the communication quality of the service bus is improved.
Referring to fig. 1, a flowchart of a service bus communication method according to a first embodiment of the present invention is shown, which includes:
step S10: and calling an online service interface by using the first task to judge whether the service bus is monitored.
Two tasks are created, such as Task-A and Task-B, where Task-A is the first Task and Task-B is the second Task. The first Task-a and the second Task-B are two independent Task processing threads, belong to the same operating system, and at least must belong to the same TCP port listening space. The service buses of the first Task-a and the second Task-B are shared, for example, the service URIs of the first Task-a and the second Task-B are TCP:// Localhost:5395, that is, the service bus has the new protocol TCP, the main level Localhost and the port 5395. The first Task-a and the second Task-B may share the service bus without knowledge of each other.
Specifically, in an embodiment, the first Task-a and the second Task-B may be sequentially used to call the online service interface to attempt to get online, the order of getting online is not limited, and it is only necessary to ensure that there is no conflict between the complete URIs, for example, the first Task-a may be used to call the online service interface at the first time, and "TCP:// Localhost:5395/NodeA/SrvA 1" may be tried to get online, if the online fails, the first Task-a may be used to call the online service interface at the second time, and "TCP:// Localhost:5395/NodeA/SrvA 2" may be tried to get online, and if the online fails, the second Task-B may be used to call the online service interface at the third time, and "TCP:// Localhost: 5395/SrvB" may be tried to get online. Specifically, an online service interface is called during online to detect whether the service bus is monitored. Specifically, part of the content of the service bus in the URI is extracted for inquiry, and it is further determined whether the service bus is monitored.
Step S11: listening for the service bus with the first task.
If the service bus is not snooped, the service bus is snooped with the first Task-A. If the first Task-A detects that the service bus is not monitored, the first Task-A is used for monitoring the service bus, and the first Task-A is successfully online.
Step S12: a registration request for the service bus by a second task is received with the first task.
The proxy of the second Task-B calls the service interface trying to register URI TCP:// Localhost:5395/SrvB to the service bus. Specifically, the second Task-B parses the service bus from the URI and sends a registration request to the service bus, and since the first Task-A has already started the service monitoring of TCP:// Localhost:5395, the first Task-A is used to receive the registration request sent by the second Task-B to the service bus.
Step S13: registering the second task to the service bus in response to the registration request with the first task.
And utilizing the first Task-A to respond to the registration request to register the second Task-B to the service bus. Specifically, the first Task-A resolves the URI according to the registration request, adds the service path of the second Task-B to the service tree of the first Task-A, and creates an agent for the second Task-B.
Step S14: and sending a registration request for the service bus to a task monitoring the service bus by using the first task.
And if the service bus is monitored, registering the first Task-A to the service bus, and specifically, sending a registration request for the service bus to a Task monitoring the service bus by using the first Task-A.
Step S15: after receiving a response to a task listening to the service bus, registering the first task with the service bus.
After a Task monitoring the service bus receives a registration request of a first Task-A, a URI is analyzed according to the registration request, a service path of the first Task-A is added to a service tree monitoring the Task of the service bus, and an agent aiming at the first Task-A is created.
In the communication method of the service bus shown in this embodiment, when a plurality of independent tasks are online serviced, service items with different tree structures can be serviced at the same service bus address.
Referring to fig. 2, a flowchart of a second embodiment of the communication method of the service bus of the present invention is shown, wherein steps S20, S21, S22, S23, S28 and S29 are the same as steps S10, S11, S12, S13, S14 and S15 in the first embodiment shown in fig. 1, except that the present embodiment further includes, after step S23:
step S24: receiving, by the first task, a connection request for the second task initiated by an external task.
At this time, if a connection request of the external Task-X to the second Task-B is detected, the first Task-A is used for receiving the connection request of the external Task-X to the second Task-B. Specifically, the external Task-X calls the service interface and initiates a connection to URI TCP:// Localhost: 5395/SrvB. The URI comprises a service bus and a service path, the service bus locates a network address of the service, and the service path locates a specific service item. The external Task-X parses the service bus from the URI and initiates a connection to the service bus.
Step S25: and completing negotiation by using the first task and the second task to obtain a connection redirection result, wherein the connection redirection result comprises a dynamic service bus address of the second task.
Specifically, after receiving a connection request for a second Task-B initiated by an external Task-X, a first Task-a analyzes a URI by using the first Task-a to further obtain a service path of the external Task-X, and sends the connection request to the registered second Task-B by using the first Task-a based on the service path. And negotiating by using the registered second Task-B and the agent of the second Task-B to obtain the connection redirection result. Specifically, the registered second Task-B sends a Connection Negotiation to the agent of the second Task, the agent of the second Task initiates a service request, generates and feeds back the Connection Negotiation to the agent of the first Task-a, and the agent of the first Task-a responds to the Connection request of the external Task-X to obtain the Connection redirection result and attaches the Connection Negotiation.
Step S26: and sending the connection redirection result to the external task by utilizing the first task.
And sending the connection redirection result to the external Task by using a first Task-A, and attaching ConNeg. Wherein the connection redirection result includes the dynamic service bus address of the second Task-B.
Step S27: establishing a point-to-point connection with the external task based on the dynamic service bus address using the second task.
Specifically, the external Task resolves the ConNeg from the redirection result to obtain the dynamic service bus address, and initiates a connection request for the second Task-B again, where the destination address of the connection already points to the dynamic service bus address of the second Task-B. And receiving a connection request initiated by the external Task based on the dynamic service bus address by using the second Task-B, authenticating the connection request, establishing point-to-point connection with the external Task based on the dynamic service bus address after the authentication is passed, and further establishing point-to-point connection between the second Task-B and the external Task-X.
In the communication method of the service bus shown in this embodiment, when a plurality of independent tasks are online serviced, service items with different tree structures can be serviced at the same service bus address. Therefore, a plurality of tasks are used for serving the same monitoring address, and the performance and the quality of the point-to-point service are improved during actual service.
Referring to fig. 3, a flowchart of a second embodiment of the communication method of the service bus of the present invention is shown, wherein steps S30, S31, S32, S33, S36 and S37 are the same as steps S10, S11, S12, S13, S14 and S15 in the first embodiment shown in fig. 1, except that the present embodiment further includes, after step S33:
step S34: and judging whether the connection between the first task and the second task is disconnected or not by utilizing the second task.
Specifically, whether the connection established between the first Task-a and the second Task-B is disconnected or not is detected by using the agent of the second Task-B.
Step S35: the service bus is snooped by the second task.
If the connection between the first Task-A and the second Task-B is disconnected, the second Task-B is used for calling a service interface, trying to get on-line, and monitoring the service bus by using the second Task-B after the on-line is successful.
Further, the second Task-B may be used to receive a registration request of the restarted first Task-a to the service bus; and utilizing the second Task-B to respond to the registration request to register the restarted first Task-A to the service bus so as to construct a service tree based on the second Task-B.
In the communication method of the service bus shown in this embodiment, when a plurality of independent tasks are online serviced, service items with different tree structures can be serviced at the same service bus address. When the main task is abnormal, the bus service can be recovered by other tasks.
Referring to fig. 4, a schematic structural diagram of an electronic device according to an embodiment of the present invention is shown, where the electronic device includes amemory 202 and aprocessor 201 that are connected to each other.
Thememory 202 is used to store program instructions implementing the method of any of the above.
Theprocessor 201 is used to execute program instructions stored by thememory 202.
Theprocessor 201 may also be referred to as a Central Processing Unit (CPU). Theprocessor 201 may be an integrated circuit chip having signal processing capabilities. Theprocessor 201 may also be a general purpose processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Thestorage 202 may be a memory bank, a TF card, etc., and may store all information in the electronic device of the device, including the input raw data, the computer program, the intermediate operation results, and the final operation results. It stores and retrieves information based on the location specified by the controller. With the memory, the electronic device can only have the memory function to ensure the normal operation. The storage of electronic devices can be classified into a main storage (internal storage) and an auxiliary storage (external storage) according to the use, and also into an external storage and an internal storage. The external memory is usually a magnetic medium, an optical disk, or the like, and can store information for a long period of time. The memory refers to a storage component on the main board, which is used for storing data and programs currently being executed, but is only used for temporarily storing the programs and the data, and the data is lost when the power is turned off or the power is cut off.
In the several embodiments provided in the present application, it should be understood that the disclosed method and apparatus may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, a division of a module or a unit is merely a logical division, and an actual implementation may have another division, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
Units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a system server, a network device, or the like) or a processor (processor) to execute all or part of the steps of the method of the embodiments of the present application.
Please refer to fig. 5, which is a schematic structural diagram of a computer-readable storage medium according to the present invention. The storage medium of the present application stores aprogram file 203 capable of implementing all the methods described above, wherein theprogram file 203 may be stored in the storage medium in the form of a software product, and includes several instructions to enable a computer device (which may be a personal computer, a server, or a network device) or a processor (processor) to execute all or part of the steps of the methods of the embodiments of the present application. The aforementioned storage device includes: various media capable of storing program codes, such as a usb disk, a mobile hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, or terminal devices, such as a computer, a server, a mobile phone, and a tablet.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.