Nothing Special   »   [go: up one dir, main page]

CN100450105C - Synchronous information interface realizing method based on JAVA information service - Google Patents

Synchronous information interface realizing method based on JAVA information service Download PDF

Info

Publication number
CN100450105C
CN100450105C CNB2005100864141A CN200510086414A CN100450105C CN 100450105 C CN100450105 C CN 100450105C CN B2005100864141 A CNB2005100864141 A CN B2005100864141A CN 200510086414 A CN200510086414 A CN 200510086414A CN 100450105 C CN100450105 C CN 100450105C
Authority
CN
China
Prior art keywords
transmit leg
message
thread
subscript
data field
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.)
Expired - Fee Related
Application number
CNB2005100864141A
Other languages
Chinese (zh)
Other versions
CN1933454A (en
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.)
ZTE Corp
Original Assignee
ZTE Corp
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 ZTE Corp filed Critical ZTE Corp
Priority to CNB2005100864141A priority Critical patent/CN100450105C/en
Publication of CN1933454A publication Critical patent/CN1933454A/en
Application granted granted Critical
Publication of CN100450105C publication Critical patent/CN100450105C/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Multi Processors (AREA)

Abstract

A method for realizing synchronous message interface based on JAVA message service includes entering synchronous request message to message interface of sending party (SP) and entering it to data region of SP through idle queue then sending it to application server through sending queue under action of sending linear program at SP, processing said request message to generate a processed result under action of receiving linear program at consuming party (CP) and entering said result to data region of CP through idle queue of CP then sending synchronous response message to application server under action of sending linear program at CP, finally sending said response message to said message interface under action of receiving linear program at SP.

Description

A kind of synchronization message interface implementation method based on the JAVA messenger service
Technical field
The present invention relates to a kind of method of the JAVA of realization application of synchronized communication mechanism, particularly relate to the method for carrying out synchronous communication between distributed JAVA application system inside or system.
Background technology
Java messenger service (JMS) can help us to reduce coupling between application program, and the resource that allows the communication between application program simultaneously and use the other side.
JMS generally comprises at least three parts: two JMS clients and a JMS server.Two clients intercom mutually by the JMS server.JMS client is to use JMS API (ApplicationProgramming Interface, API, API) to send and receive the conventional application program of message.
The JMS server can be the application program of any realization JMS standard.Some JMS servers are parts of bigger application program; Also having some is application programs of being responsible for the JMS task specially.The available use of JMS server of a lot of third party's commercial resources and some open source code resources is arranged.
Application program uses JMS two methods that intercomed mutually to select for use: JMS theme and JMS formation.Theme and formation are only had any different in some places seldom, and wherein the most tangible difference is the mode difference that their send message.
The JMS theme receives message from a JMS client and then these message is distributed to the JMS client that all are registered as theme prison hearer.On the contrary, the JMS formation only is distributed to a client with message, is formation prison hearer no matter how many client enrollments are arranged.If the formation of two or more client enrollments to one, a message stores has only a client can receive this message in formation so simultaneously.The JMS standard does not stipulate which client will receive this message.
No matter being to use the JMS theme still is the JMS formation, the type of the data that will transmit in the message all is yourself.Can be forms such as object or character string.
All be faced with the demand of synchronous communication between application program in the development process of at present a lot of application systems, generally all be to realize by socket (interface) communication, the complexity of so not only encoding, debugging and the degree of coupling between application program be still than higher, and guaranteeing to realize that cost is than higher aspect the reliability that message sends.
Summary of the invention
Technical problem to be solved by this invention provides a kind of synchronization message interface implementation method based on the JAVA messenger service, solves prior art and can not allow application program realize the technical problem of synchronous communication succinctly, reliably.
For achieving the above object, the invention provides a kind of synchronization message interface implementation method based on the JAVA messenger service, be used for synchronization request message is sent to consumption side by transmit leg through application server, and return synchronous response message, its characteristics are, comprise the steps: step 1, synchronization request message enters the message interface of transmit leg, and enter the transmit leg data field through the transmit leg idle queues, send under the thread effect at transmit leg then and send to described application server through the transmit leg transmit queue; Step 2, application program processes said request message produces a result under the receiving thread effect of consumption side, described result enters data field, consumption side through the side's of consumption idle queues, sends next synchronous response message of thread effect in consumption side and sends to described application server by data field, described consumption side through the side's of consumption transmit queue; Step 3, under the effect of transmit leg receiving thread, described response message sends to described message interface by described application server through described transmit leg data field.
Above-mentioned method, its characteristics are that described message interface connects one or more application threads, and described application thread sends described request message and receives described response message.
Above-mentioned method, its characteristics are that described application server comprises the request transfer formation that is used for transfer described request message, and the response transfer formation that is used for the described response message of transfer.
Above-mentioned method, its characteristics are that described step 1 specifically comprises:
Step a enters described message interface by using thread transmission synchronization request message;
Step b, described message interface takes down the transmit leg subscript in an idle data district from described transmit leg idle queues, described request message is put in the data field of described transmit leg subscript correspondence, more described transmit leg subscript is put into described transmit leg transmit queue;
Step c carries out the P atomic operation to the semaphore of the data field of described subscript correspondence, because described semaphore initial condition was for losing efficacy, synchronizing thread will be suspended, and carry out thread waits, will be set, so that carry out timeout treatment the time of waiting for that described semaphore enables;
Steps d, described transmit leg sends thread and remove described transmit leg subscript from described transmit leg transmit queue, described request message in the data field of described transmit leg subscript correspondence is sent to described application server, and what be sent out simultaneously also has described transmit leg subscript and a random number.
Above-mentioned method, its characteristics are that described step 2 specifically comprises:
Step e, the side's of consumption receiving thread notification application processes said request message, described application program are handled and are produced a result;
Step f, the side's of consumption receiving thread take down consumption side's subscript in idle data district, a consumption side in described consumption side idle queues, the data field of the described consumption side of mark subscript correspondence is " using ";
Step g is saved in described result and the described consumption side subscript that receives and described random number in the data field of described consumption side subscript correspondence, and described consumption side subscript is put into described consumption side transmit queue;
Step h, described consumption side sends thread described response message is sent to described application server.
Above-mentioned method, its characteristics are that described step 3 specifically comprises:
Step I, described transmit leg receiving thread is obtained described response message from described application server, and described transmit leg subscript and described random number;
Step j, find the data field of described transmit leg subscript correspondence, consistency by described random number check data, if it is consistent, then described response message is saved in the data field of described transmit leg subscript correspondence, and the semaphore in the data field of described transmit leg subscript correspondence done V operation, thereby wake the described synchronizing thread that carries out thread waits up;
Step k after described synchronizing thread is waken up, obtains described response message from the data field of described transmit leg subscript correspondence, and returns to the described application thread that sends described request message.
Above-mentioned method, its characteristics are that described application server has the disk that is used to preserve described request message and described response message, to avoid because the server accident restart and cause loss of data.
Above-mentioned method, its characteristics are that described application server can be formed a Processing Cluster, handle a plurality of transmission threads and a plurality of receiving thread that are distributed on many machines.
Technique effect of the present invention is:
By JMS sync cap method for packing of the present invention, can externally expose simple, reliable a, high-performance, the irrelevant synchronization call interface of thread, can allow application program realize synchronous communication succinctly, reliably.
Further describe specific embodiments of the invention below in conjunction with accompanying drawing.
Description of drawings
Fig. 1 is an application architecture schematic diagram of the present invention;
Fig. 2 is that internal logic of the present invention is realized and message flow chart:
Fig. 3 is the sequential flow chart that the present invention lays particular emphasis on the transmit leg interface.
Embodiment
A kind of synchronization message interface implementation method provided by the present invention based on JMS, encapsulate conversion synchronously by the asynchronous message that JMS is provided, provide a series of synchronization message calling interfaces, to satisfy the requirement that application program realizes synchronous communication succinctly, reliably.
The implementation method of the synchronization message interface based on JMS provided by the invention comprises the steps:
Step 1 makes up a JMS application server, and disposes two message queues thereon, and wherein request queue is used for the transfer synchronization request message, response queue is used for the transfer response message.
Step 2 at the transmit leg of synchronization message, makes up a message data district (adopting a fixed length structure of arrays), and the free time of setting up a thread-safe is to row and a transmit queue.Idle queue length is exactly an array length when initial, and transmit queue length is 0 when initial.To setting up a semaphore in each unit, data field, the semaphore initial condition was for losing efficacy simultaneously.
Step 3 at message sender, makes up a request message and sends thread, and this thread obtains message specially from transmit queue, and sends it in the transmit queue of JMS server.
Step 4 in the consumption side of synchronization message, makes up a message data district (adopting a fixed length structure of arrays) equally, and the free time of setting up a thread-safe is to row, a response message transmit queue.Idle queue length is exactly an array length when initial, and transmit queue length is 0 when initial.
Step 5 in information consumption side, makes up one or more request message receiving thread and a response message transmission thread, and this thread obtains message specially from the response message transmit queue, and sends it in the response queue of JMS server.
Step 6, when the transmit leg application program sends a synchronization request message, the synchronized transmission interface at first takes down the subscript in an idle data district from the idle queues head, the message that needs are sent is put in this data field, subscript is put in the transmit queue again, and the semaphore to this time target data field carries out the P atomic operation at last, because data field semaphore initial condition was for losing efficacy, the sync cap thread will be suspended, and the time that wait-semaphore enables must be set, so that carry out timeout treatment.
Step 7, request message send thread and remove this data field subscript from transmit queues, the message in this data field is sent in the request queue of JMS server, be sent out simultaneously also have this subscript and a random number; And then the receiving thread of synchronization message consumption side has obtained this request message and subscript and random number from the request queue of JMS server.
Step 8, the receiving thread notification application of consumption side is handled this request message, after finishing dealing with, from the idle queues head, take down the subscript in an idle data district, the data field of this subscript correspondence of mark is Used then, and with result, adds the array index and the random number that receive, be saved in together in the data field of consumption side, again subscript be put in the transmit queue.And send thread by response message and send in the response queue in the JMS server.
Step 9, requesting party's response message receiving thread is obtained response message from the response queue of JMS server, and array index and random number; And then, find the data field of subscript correspondence, by the consistency of random number check data,, then response message is saved in the data field, and the semaphore in this data field is done V operation if consistent, thus the thread of wake-up waiting.
Step 10 after synchronized transmission interface thread is waken up, obtains response message from the data field, and returns to the application program of initiating synchronization call.Whole synchronous flow process finishes.
The above-mentioned synchronization message interface implementation method based on JMS because the JMS server provides the function that message is kept at the local disk file, can effectively avoid JAVA application server accident to restart the problem of back loss of data.
The above-mentioned synchronization message interface implementation method based on JMS can realize distributed treatment and high performance message route; If have a plurality of transmission threads and a plurality of receiving thread to be distributed in respectively on many machines, can form a Processing Cluster by the JMS server.
Accompanying drawing of the present invention is based on the application architecture schematic diagram that the system of the synchronization message interface of JMS: Fig. 1 is JMS, as shown in FIG., message-oriented middleware among the figure is JMS server (also can adopt other middleware) wherein here, the synchronization message transmission interface allows a plurality of client threads to carry out concurrent operations, when sync cap is provided, the interface of asynchronous transmission also is provided, asynchronous transmission only need be disposed a JMS message queue, and need not carry fields such as array index and random number in JMS message.The benefit of encapsulation asynchronous message is, can mask the difference of the transmission performance that different JMS servers brings, and application program is returned after asynchronous message is put into the data field immediately.
Fig. 2 is that the synchronous package interface internal logic of JMS is realized and message flow chart.Can see in the drawings,, all form by idle queues, transmit queue, data field, transmission thread and receiving thread transmit leg and recipient.
Which unit, data field is idle queues writing down is not used as yet, needs emphasis to consider the best joint of thread independence, high-performance, minimum Memory Allocation etc. in the realization of idle queues.
Which unit, data field transmit queue is writing down there are data to be sent, and transmit queue writes the subscript information of data field by the sync cap thread, therefrom reads by sending thread.
Send unique work that thread does and be exactly reading of data from transmit queue again and again, and send it in the request queue of JMS.What deposit in the queue unit of reading is the subscript of a data field, transmit queue begins the next data cell in the processing queue after the data to be sent in this subscript, the information such as array index, random number that add are sent completely by concrete JMS message transmission interface immediately; If there are not data in the formation, send thread and then be in wait state.A large amount of The performance test results show that a performance that sends thread can meet the demands.
Receiving thread mainly is responsible for receiving JMS message from JMS associated queue, and at the synchronization request transmitter side, receiving thread activates waiting transmission interface thread by the method for enable signal amount.At the synchronization request receiver side, receiving thread is responsible for notifying upper level applications to handle related news, and information such as return results and array index, random number are saved in the data field.1 or 2 receiving thread of general use can satisfy instructions for use.
Message flow is indicated by the arrow among the figure, and wherein dotted portion is represented the inside realization in the package interface, and the method that solid line is partly represented to call concrete JMS server and provided is realized.
Fig. 3 is the sequential flow chart that lays particular emphasis on the transmit leg interface, and recipient's interface sequence is basic identical.As follows to process description wherein:
1, application call synchronized transmission interface sends content;
2, the synchronized transmission interface is saved in data in the data field, array index is put in the transmit queue, and the beginning wait-for-response;
3, the backstage sends thread and sends among the request Queue of JMS message in the JMS server;
4, receive request message among the request Queue of response side from the JMS server.
5, response side handles request message
6, response side sends to result among the response Queue of JMS server.
7, receiving thread receives response message from JMS response Queue
8, receiving thread is saved in response message in the corresponding data field according to the array index in the response message, and notice is waited for thread
9, after the sync cap of Deng Daiing is activated, the result is returned to application layer.
From top embodiment, as can be seen,, can externally expose simple, reliable a, high-performance, the irrelevant synchronization call interface of thread by JMS sync cap method for packing of the present invention.
Certainly, the present invention also can have other various embodiments, under the situation that does not deviate from spirit of the present invention and essence thereof, those of ordinary skill in the art are when making various corresponding changes and distortion according to the present invention, such as not adopting the JMS server, and directly by local queue, socket etc. can adopt the present invention to realize synchronous communication.But these corresponding changes and distortion all should belong to the protection range of the appended claim of the present invention.So the above is preferred embodiment of the present invention only, be not to be used for limiting practical range of the present invention; Every according to equivalence variation and modification that the present invention did, all contained by claim of the present invention.

Claims (8)

1, a kind of synchronization message interface implementation method based on the JAVA messenger service is used for synchronization request message is sent to consumption side by transmit leg through application server, and returns synchronous response message, it is characterized in that, comprises the steps:
Step 1, synchronization request message enter the message interface of transmit leg, and enter the transmit leg data field through the transmit leg idle queues, send under the thread effect at transmit leg then and send to described application server through the transmit leg transmit queue;
Step 2, application program processes said request message produces a result under the receiving thread effect of consumption side, described result enters data field, consumption side through the side's of consumption idle queues, sends next synchronous response message of thread effect in consumption side and sends to described application server by data field, described consumption side through the side's of consumption transmit queue;
Step 3, under the effect of transmit leg receiving thread, described response message sends to described message interface by described application server through described transmit leg data field.
2, method according to claim 1 is characterized in that, described message interface connects one or more application threads, and described application thread sends described request message and receives described response message.
3, method according to claim 1 is characterized in that, described application server comprises the request transfer formation that is used for transfer described request message, and the response transfer formation that is used for the described response message of transfer.
4, according to claim 1,2 or 3 described methods, it is characterized in that described step 1 specifically comprises:
Step a enters described message interface by using thread transmission synchronization request message;
Step b, described message interface takes down the transmit leg subscript in an idle data district from described transmit leg idle queues, described request message is put in the data field of described transmit leg subscript correspondence, more described transmit leg subscript is put into described transmit leg transmit queue;
Step c carries out the P atomic operation to the semaphore of the data field of described subscript correspondence, because described semaphore initial condition was for losing efficacy, synchronizing thread will be suspended, and carry out thread waits, will be set, so that carry out timeout treatment the time of waiting for that described semaphore enables;
Steps d, described transmit leg sends thread and remove described transmit leg subscript from described transmit leg transmit queue, described request message in the data field of described transmit leg subscript correspondence is sent to described application server, and what be sent out simultaneously also has described transmit leg subscript and a random number.
5, method according to claim 4 is characterized in that, described step 2 specifically comprises:
Step e, the side's of consumption receiving thread notification application processes said request message, described application program are handled and are produced a result;
Step f, the side's of consumption receiving thread take down consumption side's subscript in idle data district, a consumption side in described consumption side idle queues, the data field of the described consumption side of mark subscript correspondence is " using ";
Step g is saved in described result and the described consumption side subscript that receives and described random number in the data field of described consumption side subscript correspondence, and described consumption side subscript is put into described consumption side transmit queue;
Step h, described consumption side sends thread described response message is sent to described application server.
6, method according to claim 5 is characterized in that, described step 3 specifically comprises:
Step I, described transmit leg receiving thread is obtained described response message from described application server, and described transmit leg subscript and described random number;
Step j, find the data field of described transmit leg subscript correspondence, consistency by described random number check data, if it is consistent, then described response message is saved in the data field of described transmit leg subscript correspondence, and the semaphore in the data field of described transmit leg subscript correspondence done V operation, thereby wake the described synchronizing thread that carries out thread waits up;
Step k after described synchronizing thread is waken up, obtains described response message from the data field of described transmit leg subscript correspondence, and returns to the described application thread that sends described request message.
7, method according to claim 4 is characterized in that, described application server has the disk that is used to preserve described request message and described response message, to avoid because the server accident restart and cause loss of data.
8, method according to claim 4 is characterized in that, described application server can be formed a Processing Cluster, handles a plurality of transmission threads and a plurality of receiving thread that are distributed on many machines.
CNB2005100864141A 2005-09-13 2005-09-13 Synchronous information interface realizing method based on JAVA information service Expired - Fee Related CN100450105C (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CNB2005100864141A CN100450105C (en) 2005-09-13 2005-09-13 Synchronous information interface realizing method based on JAVA information service

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CNB2005100864141A CN100450105C (en) 2005-09-13 2005-09-13 Synchronous information interface realizing method based on JAVA information service

Publications (2)

Publication Number Publication Date
CN1933454A CN1933454A (en) 2007-03-21
CN100450105C true CN100450105C (en) 2009-01-07

Family

ID=37879078

Family Applications (1)

Application Number Title Priority Date Filing Date
CNB2005100864141A Expired - Fee Related CN100450105C (en) 2005-09-13 2005-09-13 Synchronous information interface realizing method based on JAVA information service

Country Status (1)

Country Link
CN (1) CN100450105C (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102231755A (en) * 2011-06-20 2011-11-02 中兴通讯股份有限公司 Method and device for unified processing of mobile social network software (SNS) application
CN102404404B (en) * 2011-09-07 2017-07-28 航天科工仿真技术有限责任公司 A kind of distributed WEB is applied and remote equipment information communication method
CN103064778B (en) * 2011-10-20 2015-09-09 阿里巴巴集团控股有限公司 A kind of server performance method of testing, Apparatus and system
CN102629221B (en) * 2012-02-28 2014-11-19 华为技术有限公司 Task synchronization method, device and system for distributed shared memory structure
CN104333515B (en) * 2014-11-14 2018-07-06 中国建设银行股份有限公司 A kind of SWIFT message processing methods and device
CN106789245A (en) * 2016-12-22 2017-05-31 浪潮通信信息系统有限公司 A kind of instruction based on JMS performs service aid and method
CN111158923B (en) * 2019-12-30 2023-05-12 深圳云天励飞技术有限公司 Interface calling method and device, electronic equipment and storage medium
CN111447263A (en) * 2020-03-24 2020-07-24 中国建设银行股份有限公司 Message communication system
CN112685190A (en) * 2020-12-30 2021-04-20 平安普惠企业管理有限公司 Synchronous calling method and system based on message queue and computer equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP0565849A2 (en) * 1992-04-14 1993-10-20 International Business Machines Corporation A method and system for synchronizing threads within a process
JP2004030312A (en) * 2002-06-26 2004-01-29 Mitsubishi Electric Corp Method for controlling multithread synchronization
CN1584842A (en) * 2004-06-09 2005-02-23 中兴通讯股份有限公司 Method for applied server of computer system
CN1589442A (en) * 2001-10-05 2005-03-02 Bea系统公司 System for application server messaging with multiple dispatch pools
CN1630852A (en) * 2001-09-28 2005-06-22 英特尔公司 Flexible acceleration of JAVA thread synchronization on multiprocessor computers

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP0565849A2 (en) * 1992-04-14 1993-10-20 International Business Machines Corporation A method and system for synchronizing threads within a process
CN1630852A (en) * 2001-09-28 2005-06-22 英特尔公司 Flexible acceleration of JAVA thread synchronization on multiprocessor computers
CN1589442A (en) * 2001-10-05 2005-03-02 Bea系统公司 System for application server messaging with multiple dispatch pools
JP2004030312A (en) * 2002-06-26 2004-01-29 Mitsubishi Electric Corp Method for controlling multithread synchronization
CN1584842A (en) * 2004-06-09 2005-02-23 中兴通讯股份有限公司 Method for applied server of computer system

Also Published As

Publication number Publication date
CN1933454A (en) 2007-03-21

Similar Documents

Publication Publication Date Title
CN106713226B (en) A kind of remote procedure call processing method and system for distributed system
CN110134534B (en) System and method for optimizing message processing for big data distributed system based on NIO
CN103927218B (en) Event distributing method and system
CN101651698B (en) Transmission method for publish/subscribe system based on NIO and IO
CN108769099A (en) A kind of implementation method of the message duplicate removal of message-oriented middleware
US20040068479A1 (en) Exploiting asynchronous access to database operations
CN110677277B (en) Data processing method, device, server and computer readable storage medium
CN111212085B (en) Method for synchronously calling Internet of things platform, internet of things system and network equipment
CN109547162B (en) Data communication method based on two sets of one-way boundaries
CN101383839A (en) Data distribution system based on data server and implementation method
CN108494817A (en) Data transmission method, relevant apparatus and system
CN100450105C (en) Synchronous information interface realizing method based on JAVA information service
CN103888441A (en) Information transmitting method between application and protocol stack and processing device
CN110309231A (en) A kind of method of data synchronization and system across computer room
CN111641700A (en) Method for realizing management and retrieval of metadata based on Ceph object storage
CN107688512A (en) One kind optimization virtual-machine data backup method and system
CN103577257A (en) REST (representational state transfer) service method, device and system
CN110083468A (en) A kind of data transmission method, electronic device and storage medium
CN116382943A (en) Sequential message processing method, bus system, computer device, and storage medium
CN106803841B (en) Method and device for reading message queue data and distributed data storage system
CN105208004A (en) Data input method based on OBD equipment
CN109388501B (en) Communication matching method, device, equipment and medium based on face recognition request
CN103338160B (en) Based on optimization system and the optimization method of the polling service of buffer queue
CN114528119A (en) Scheme for shortening response time by switching asynchronous mode to synchronous mode based on publish-subscribe queue
CN107943541B (en) Communication method of Windows local component

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20090107

Termination date: 20150913

EXPY Termination of patent right or utility model