Architecting Distributed Systems with Web Services, SESTEMS WITHTECTIN

zhaozj2021-02-16  160

Architecting Distributed Systems with Web Services, SESTEMS WITHTECTIN

Although SOAP is typically demoed withsimple RPC-based Web services, such as SkatesTown's inventory check service, the SOAP specification does not mandate any particular communication mechanism or interaction pattern between the participants of a Web-service-enabled distributed system. System designers basically have complete control over the system architecture, choice of communication protocols, message routing, intermediary configuration, and so on. The hard part about having so much flexibility is that without solid experience with distributed systems and good judgment, it is easy to make sub-optimal choices .

The most commonly asked questions about distributed systems based on Web services center around a long-running debate in distributed computing circles regarding the rules and regulations for using RPC and messaging (often identified as Message Oriented Middleware-MOM) to solve problems. Typically, the debate takes the unnecessarily polarized form of "MOM vs. RPC." The fact of the matter is that both messaging and RPC play significant, albeit different, roles in distributed computing. Both approaches continue to be very relevant in the era of Web services.

Unfortunately, a lot of confusion exists about the meaning of the terms, the capabilities of messaging and RPC systems, and the scenarios in which they are best applied. Service-oriented architectures fundamentally can support both models. Therefore, to best take advantage of Web services, it helps to have a good understanding of both. What follows is a brief analysis of the two approaches and their relation to SOAP and Web services. Given that people are generally more familiar with RPCs, we start with a discussion of messaging in its Many Forms.Messaging

As a model for distributed computing, messaging refers to a mechanism for getting systems to interact via the passing of messages. A message is a single unit of communication encapsulating some information. (A SOAP message is a great example.) This is where the differences Begin. Messaging Models CAN Vary Signiffantly Based On The Following Criteria:

Number of participants and their Organization Interaction Patterns Synchronicity of Message EXCHANGES DIRECT VERSUS Queued Messaging Quality Of Service (QoS) Message Format

Message participants

There are three different ways to organize messaging participants (see Figure 3.12). The simplest case is 1-to-1 (point-to-point) messaging, which involves only two systems. An example could be an e-commerce scenario where the CLIENT Application Submits a Purchase ORDER TO A DIGITAL MARKETPLACE. In this case, the sender neseds to know where to send the message.

Figure 3.12 messaging patterns.

A slightly more complicated organization is 1-to-many messaging, where the sender sends a single message but copies of it go to multiple recipients. This is often referred to publish / subscribe or topic-based messaging. The idea is that the sender is a publisher that sends a message to a "topic" and that the recipients are all the systems that have subscribed to receive notifications on this topic. E-mail distribution lists are a good example of this type of messaging. The name of the distribution list is the topic, and the subscribers are all the e-mail addresses on the list.Finally, many-to-many messaging involves a pattern of message exchange among any number of participants. Clearly, in this case, some system in the middle ( NEEDS to Direct Message Traffic. This is described by The Cloud In Figure 3.12.

Intertion Patterns

There are four common messaging interaction patterns (see Figure 3.13). One-way (fire-and-forget) messaging involves the simple sending of a message from one system to another. No response is generated at the application level. Of course, depending on the transport (such as HTTP), a response might be generated at the network level. In the case of request-response messaging, a response message is generated for every request message. The response message is sent from the target of the request message TO ITS Source. Chapter 6 Describes How Requests and RESPONSES CAN Be Correlated and How Multiple Request-Response Pairs CAN Be Organized Into Logical "Conversations"

Figure 3.13 intertion patterns.

The other two interaction patterns, notification and notification-response, are mirror images of one-way and request-response. They are callback patterns. Rather than a client system pushing messages to a server system, the server system is pushing messages to the client . The stock ticker application you might have on your desktop is a perfect example of notification combined with publish-subscribe messaging. Chapter 6 gets into more detail about Web service interaction patterns.Synchronicity

Messaging can be either synchronous or asynchronous. In synchronous messaging, a send operation does not complete until the target of the message has finished processing the message. Asynchronous messaging is harder to define. Typically, the send operation will return immediately (or very quickly) Before The Target Has Processed The Message. Response Messages, IF ANY, TYPICLY Arrive Via Callbacks.

Direct vs. Queued Messaging

The synchronicity of messaging is controlled by the presence of messaging middleware, particularly queuing systems. Direct messaging works without any middleware present. For messages to be exchanged, a direct connection between the source and the target (s) must be available. This is why IT IS Sometimes Referred to As Connection-Oriented Messaging. You can get some amount of asking threads to manage the sending and receiving of messages.

Indirect messaging involves some type of message queuing. Queues provide message buffering and dispatch capabilities. Consider the e-mail server example from earlier in the chapter. An e-mail server is a perfect example of a message queuing system. When you send an e -mail message, your e-mail client does not contact the e-mail client of the person you are trying to reach. Instead, your e-mail client sends the message to a local e-mail server. The server saves the message in some safe place and waits for a good moment to send it out. Typically, many messages are sent at once. This is the buffering function. The dispatch function has to do with the e-mail server inspecting the target e-mail addresses and deciding where to forward the e-mail message. In some cases, an e-mail message will make several hops between e-mail servers before it arrives at the destination e-mail server where your mail client can read it. This configuration is so powerful Because IT Works Even in The Case WHERE M Ail Clients and Even Some Mail Servers Are Offline for Long Periods of Time. A Mail Server Will Keep Trying to Send E-Mail for Several Days and will store receivers.

Figure 3.14 contrasts direct messaging (the topmost configuration) with a number of possible queuing configurations. In the second and third configurations, the queuing system acts primarily as a message buffer. For example, if the receiver is not on the network, the message will still be safely stored in the queue. The last configuration is the most interesting, in that the message can be moved from the local to the remote system without either the sender or the receiver being online-the message queuing systems can do the job by themselves ...........................

Quality of Service

Another important aspect of messaging is quality of service (QoS). Direct messaging exhibits the QoS parameters with which we are most familiar, such as security and transaction management. When queuing is in use, other types of QoS become available. For example, messages Can Be Stored in The Queuing Server in Various Ways: In Memory (The Fastest Queuing Mechanism But One That Does Not Guarantee Against System Failure) Or in Some Persistent Store, Such as a dbms.

Further, transactions can guarantee that the message is sent to the receiver once and only once or not at all. In the case of message delivery failure, QoS policy might dictate that a failure notification is sent to the message sender. In addition, it is common QoS policy to send acknowledgement notifications that the message has been successfully delivered to the receiver. These types of QoS considerations are very relevant to Web services. Chapter 5 looks in more detail at some QoS aspects.

Message Format

The last but not least important aspect of messaging is the format of message data. Most messaging systems allow the transfer of text and binary data, to enable the easy transfer of XML. Some newer messaging systems treat XML messages specially and try to use an optimized XML encoding format. There is also the notion of queues that can automatically allow only XML messages that comply with certain schema. Some platform-focused messaging systems, such as Java Messaging Service (JMS) middleware and Microsoft's .NET messaging server, also allow for THE Automatic Serialization of Application Data (Java Objects in the case of jms and common language runtime [clr] Data Structures in the case of microsoft) .Messaging Versus RPC

If messaging is all about possibilities and variations, RPCs are much more constrained. As the name suggests, the goal of RPCs is to make the invocation of remote code seem like a local procedure call (LPC). To make an RPC call, you need The Following Information:

A Target to Invoke An Operation Name Optionally, Parameters To Pass to the Operation

Therefore, whereas messaging is primarily about data (which can be in any conceivable format), RPCs are about combining specific application-level data with remote code. This is the one fundamental difference between messaging and RPC. A nice side-effect is that programmers .

Another way to state the main difference between messaging and RPC is to note that messaging deals with generic APIs such as sendMessage (), getMessage (), and registerMessageResponseCallback (), whereas RPCs deal with special-purpose APIs that vary based on the interface of the target that is being invoked. For example, if you are trying to invoke a remote EJB that has a processOrder () method, you will most likely call the processOrder () method of a local object that acts like a proxy to the remote EJB . Chapter 6 discusses this topic in much more detail.Another key difference between RPCs and messaging is that RPCs are direct invocations There is no queuing mechanism;. the backend must be running and it must be directly accessible at a well-known location This. .

Finally, extensive use of RPCs tends to result in somewhat brittle distributed systems. Because the APIs are fine-grained, even small changes in the data being passed around can break the system. Messaging uses much rougher-grain data exchanges and is therefore more likely To Sustain Small Changes in The Data Being Exchanged WITHOUT FAILURE.

Apart from these Key Differences, RPCS and Messaging Have Many Similarities:

RPCs can be implemented on top of a request-response messaging pattern. Contrary to popular belief, however, RPCs do not have to have a request-response messaging pattern. Some systems support one-way RPCs. In addition, RPCs do not have to be synchronous. Some systems automatically spawn threads to wait in the background for RPC responses. RPCs and messaging share many of the same QoS requirements such as security and transaction management. Direct, synchronous, 1-to-1 messaging can be simulated via a simple RPC, eg, void sendMessage (data) .It should become clear by now that the real issue is not which of the two approaches to distributed computing is better (the simple interpretation of "messaging vs. RPC") but when each approach should be used in the world of Web services. to answer this question, after we have mentioned so many possible variations of both messaging and RPC, it helps to establish some stereotypes. When working with Web services, it will generally be the case tha T:

RPCs will be direct, synchronous, request-response invocations that pass encoded application-level data structures from a client to a target backend that implements the RPC functionality. Messages will carry XML data. The interaction pattern is most likely to be one-way or .

.. In both cases, messages will be represented on the wire using SOAP QoS-related information that is part of the message will be represented as message headers A good example would be an authentication header that carries a username and password; Chapter 5 shows an example.Table 3.2 presents a number of benefits and concerns about using messaging and RPC. based on these and the current state-of-the-art in Web service middleware and tooling, we would recommend that you go with a simple RPC-based solution OR A DIRECT MESSAGING SOLUTION UNSS DISCONNECTED OPERATION WILL BE OF BENEFIT, The System Requires 1-To-Many Interacts, or Synchronous Operation IS Causeing Performance Problems.

Table 3.2 PROS AND CONS OF MESSAGING AND RPC for Web Services

Pros Cons Direct messaging The basic messaging APIs are very simple. Any data can be passed. Separates data from the code that operates on it. Applications must perform manual data encoding / decoding. Queued messaging Same as above, plus ... Asynchronicity spreads the load and improves performance. Allows for disconnected operation. Allows for 1-to-many and many-to-many interactions. Same as above plus ... Most useful forms of messaging require a queuing infrastructure. Current message queuing products do not interoperate well . Asynchronicity makes programming more difficult. RPC Local APIs match backend APIs. Synchronicity makes programming easy. Application data is automatically encoded / decoded. Exceptions provide a good error-handling mechanism. RPC products interoperate reasonably well. Synchronicity can cause bottlenecks. backend must be Running for rpcs to succeed. Only 1-to-1 Interactions Are Supported.

We would expect that as messaging middleware vendors embrace Web services to a greater extent and as more Web services become increasingly used in the context of complex business process workflows, the importance of Web service messaging will grow Broad standardization efforts such as ebXML (http.: //www.ebxml.org) And Java Api for XML Messaging (jaxm, http://java.sun.com/xml/jaxm/index.html) WILL HELP Speed ​​Up The Process.soap-based RPCS

So far in this chapter we have presented several examples of SOAP-based RPC without ever mentioning the details of representing RPCs in SOAP messages as described by the SOAP specification. The rules are very simple.

Recall that to invoke an RPC, you need a target URI, an operation name, some parameters, and any amount of context information (such as security context). Any such context information is modeled as SOAP headers.

SOAP's RPC binding does not specify how the target URI is going to be provided. In other words, it leaves it up to the SOAP processor to determine how to dispatch a SOAP RPC request to a target backend. There are three common ways to do this Dispatch. Two of these area http-specific, and the other is based on the contents of the soap message:

In the case of HTTP, the SOAP processor can dispatch based on the target URI (as in the inventory check example). Alternatively, it may dispatch based on the value of the SOAPAction HTTP header that comes as part of the HTTP request. Alternatively, IT CAN Use the value of the namespace uri for the first element inside the soap body.

MOST Web Services Engines Do Not Support All these Dispatch Mechanisms. Axis Can Be Configured to Work with any combination.

In the language of the SOAP encoding, the actual RPC invocation is modeled as a struct. The name of the struct (that is, the name of the first element inside the SOAP body) is identical to the name of the method / procedure. This is not a problem, because the character set of XML elements is a superset of the character set of valid identifier names in programming languages. Every in and in-out parameter of the RPC is modeled as an accessor with a name identical to the name of the RPC parameter and type identical to the type of the RPC parameter mapped to XML according to the rules of the active encoding style. The accessors appear in the same order, as do the parameters in the operation signature.The RPC response is also modeled as a struct. By convention, the name of the struct is the same as the name of the operation, with Response appended to it. There are accessors for the operation result and all in-out and out parameters. The result is the first accessor, Followed by the parameters In The ORDER THEY APPEAR in The Operation Signature. by Convertion, The Result Element's name is the Same as the name of the operation, with result appended to it.

Java developers are not used to the concept of in-out or out parameters because, typically, in Java all objects are automatically passed by reference. When using RMI, simple objects can be passed by value, but other objects are still passed by reference. In this Sense, Any Mutable Objects (ones whose state can be modifi) Are Automatical Treated as in-out parameters.

In Web services, the situation is different. All parameters are passed by value. SOAP has no notion of passing values ​​by reference. This design decision was made in order to keep SOAP and its data encoding simple. Passing values ​​by reference in a distributed system requires distributed garbage collection. This not only complicates the design of the system but also imposes restrictions on some possible system architectures and interaction patterns. For example, how can you do distributed garbage collection in a queued messaging architecture when the requestor and the provider of a service can both be offline at the same time? Therefore, for Web services, the notion of in-out and out parameters does not involve passing objects by reference and letting the target backend modify their state. Instead, copies of the data are exchanged. IT is kil t t i t The the the actual state of the object thing haas been passed in To the client method Different Web Service Clients Might Have Different Ways to do this.

Consider The Following Operation Signature:

Boolean Docheck (in String Sku, In Int Quantity, Out Int NumInstock)

Some Possible SOAP RPC Request and Response Bodies Are:

947-Ti

1

True

150

Of course, if a description of the operation is available, you can generate a schema for all the elements in the SOAP body Doing so would eliminate the need to use xsi:. Type everywhere in the SOAP message Chapter 6 looks in more detail at. The mechanisms for doing this.

SOAP-BASED MESSAGING

The technical term for non-RPC SOAP messaging is document-centric messaging. The name comes from the fact that the data sent over SOAP is represented as an XML document embedded inside the SOAP envelope. Although the RPC binding for SOAP has a number of rules governing the representation and encoding of operation names and parameters, simple SOAP messages have absolutely no restrictions as to the information that can be stored in their bodies. in short, any XML can be included in the SOAP message. The next section of this chapter shows An example of soap-based message.

转载请注明原文地址:https://www.9cbs.com/read-8540.html

New Post(0)