24

What are the big advantages from JMS over Webservices or vice versa?

(Are webservices bloated? Is JMS overall better for providing interfaces?)

9 Answers 9

29

EDITED after correction from erickson:

JMS requires that you have a JMS provider, a Java class that implements the MessageListener interface for processing messages, and a client that knows how to connect to the JMS queue. JMS means asynchronous processing - the client sends the message and doesn't necessarily wait for a response. JMS can be used in a point-to-point queue fashion or publish/subscribe.

"Service" is a fluid term. I think of a service as a component that lives out on a network and advertises a contract: "If you send me X I'll perform this task for you and return Y."

Distributed components have been around for a long time. Each one communicated using a different protocol (e.g., COM, Corba, RMI, etc.) and exposed their contract in different ways.

Web services are the latest trend in distributed services. They use HTTP as their protocol and can interoperate with any client that can connect via TCP/IP and make an HTTP request.

You can use SOAP or RPC-XML or REST or "contract first" styles, but the underlying idea of a distributed component using HTTP as its protocol remains.

If you accept all this, web services are usually synchronous calls. They need not be bloated, but you can write bad components in any style or language.

You can start designing any distributed component by designing the request and responses first. Given those, you choose JMS or web services based on what kind of clients you want to have and whether or not the communication is synchronous or asynchronous.

3
  • 3
    JMS is not Java-only. JMS was carefully designed to allow vendors to provide Java interfaces to their proprietary message services. There are also JMS providers for open messaging protocols like ebXML. Both approaches allow a JMS-based Java application to interoperate with messaging applications on other platforms.
    – erickson
    Commented May 12, 2009 at 23:04
  • 1
    So WS-* and JMS are both ways to advertise contracts for distributed communication. When should I use WS-* and when should I use JMS? I read unf.edu/~ree/1024IC.pdf . JMS outperforms WS-* for small data sets there and offers support for "offline targets" and WS-* can handle larger amounts of data better. Is that the only advantage/disadvantage? Is the afford for writing JMS endpoints equal to WS-* endpoints? How to make an decision between one of them? It seems JMS is more lightweight isn't it?
    – Martin K.
    Commented May 13, 2009 at 6:33
  • 2
    When you say "large amounts", what do you mean? WS-* are poor at handling very large data because of the difficulty of large XML documents. Most JMS aren't optimized to handle huge data either, but since there is more latitude for implementation in a proprietary system, a JMS provider is in a better position to handle it. As for which to choose, it depends on the application, and how messages are to be used, not so much on the message itself (size and format). And, don't forget, a JMS provider could be implemented with WS-* services.
    – erickson
    Commented May 13, 2009 at 16:25
7

Message based systems, including JMS, provide the ability to be "chronologically decoupled" from the other end. A message can be sent without the other end being available.

All other common A2A approaches require the partner to be able to respond immediately, requiring them to be able to handle peak loads, with little ability to spread processing.

4

I'd say the biggest distinction is that JMS is message-oriented, rather than RPC-oriented. Out-of-the-box, most JMS providers support high-level protocols that perform retries, prevent duplicates, and support transactions.

There are many applications where these capabilities are unnecessary. But where they are needed, building them yourself on top of an RPC mechanism is complicated, expensive, and error-prone.

2
  • HTTP and XML and SOAP does not require an RPC model. In fact the WCF within .NET has options for dealing communications as incoming and outgoing messages. It's very message-oriented. I think there are similar metaphors available in Java-based "web services" stacks.
    – Cheeso
    Commented May 12, 2009 at 23:36
  • Sure, you can pass "messages" over RPC, and Java does provide that capability as well. By "message-oriented", I meant asynchronous, reliable, and transactional, which are things you don't get from a REST or WS-* based web service... although you can, of course, define the necessary higher-level protocol using individual unreliable, synchronous operations.
    – erickson
    Commented May 12, 2009 at 23:46
3

Web services are an implementation of Services Oriented Architectures (SOA). A SOA has three parties: a provider, a broker, and a requester, which are loosely coupled. The provider offers a business service that represents a particular implementation, which is not directly visible to the requester. The requester learns from the broker the information structure that it has to send and receive from the provider and what protocol to use to access that service. The requester has no knowledge of the way the provider implements the business service.

Web services are defined as required business interfaces between a requester and a provider, and not as a common pipe for all business requests. There are several variables that can characterize web services, including that:

  • They can be tightly coupled, and their deployment can be based on the use of invocation frameworks.
  • They can perform either in a synchronous request/reply mode or in an asynchronous mode.
  • They can be exposed by J2EE or non-J2EE providers.
  • They might or might not offer support for transactions and security.

JMS is an asynchronous message-based interface. You can also use JMS to access business logic distributed among heterogeneous systems. Having a message-based interface enables the following functions:

Point to point and publish/subscribe mechanisms. Message-based frameworks can push information to other applications without their requesting it explicitly. The same information can be delivered to many subscribers in parallel.

Rhythm independence. JMS frameworks function in asynchronous mode but also offer the capability of simulating a synchronous request/response mode. This allows source and target systems to work simultaneously without having to wait for each other.

Guaranteed information delivery. JMS frameworks can manage the messages in transactional mode and ensure message delivery (but without any guarantee of timeliness of delivery).

Interoperability between heterogeneous frameworks. The source and target applications can operate in heterogeneous environments without having to handle problems of communication and execution related to their respective frameworks.

Making exchanges more fluid. The switch to message mode allows finer-grained information exchange.

enter image description here

Source

2

let me talk w.r.t SOAP protocol implementation of web services...which is better JMS vs webservices....JMS provides transport protocol and it is underlying messaging provider which depicts how much good or bad is ur JMS provider for e.g. MQ is a powerful reliable JMS provider where as SOAP protocol can be considered both application level protocol and can also be treated as a transport protocol (in sense of SOAP/HTTP)...the beenfit of SOAP is in support of XML based standard...as an application level protocol, we consider SOAP as a message to be passed from one system to another over any transport protocol where as a transport protocol, SOAP can be considered as a container for transporting a payload(message data)...SOAP/HTTP can also be looked as JMS meesaging provider....but in latter form, HTTP has issue of reliablity, as it invloves errors related to networking, socket connections, bandwidth etc...so keeping long story short, JMS with reliable message provider makes it good standard for interacting with good transport protocol where webservice as an application level protocol makes disparate application to communicate using XML-like-SOAP protocol...hope this clarifies...

1

From the ones I've done here's the differences I've found: JMS - I'm tied to the JMS provider - however I have choices of implementation type (pub/sub, point to point) Web Service - easier to handle/architect - however its more of a direct communication between the boxes. Lots of tools to use to do the development - and a clean interface (WSDL's) so implementor and caller can be independent.

Which one to use? Depends on what the problem is.

1
  • 1
    WSDL is by no means a guarantee of independence. If you expose Java classes, you have to make them available to both client and server. Changes in those classes exposed in WSDL require updates to both. "contract first" XML is a better way to go.
    – duffymo
    Commented May 12, 2009 at 23:26
1

Would add this as a comment to dyffymo's post, but don't yet have the rep.

Quoting from your answer:

"Web services are the latest trend in distributed services. They use HTTP as their protocol and can interoperate with any client that can connect via TCP/IP and make an HTTP request.

You can use SOAP or RPC-XML or REST or "contract first" styles, but the underlying idea of a distributed component using HTTP as its protocol remains."


I'm assuming by web services you mean the WS-* set of protocols, WSDL, and SOAP. If so, then none of these require the use of HTTP as the "transport" protocol. The SOA set of protocols was designed to be agnostic as to the tramission protocols used, so you can use HTTP, NamedPipes, raw TCP, and even JMS as the means to transmit messages to and from a web service.

So in the case of direct use of JMS vs. use of "web services" I think it mostly boils down to tooling, comfort level, and whether you really need direct access to some JMS specific feature (which using WS-* would hide from you). At this point I would think that only fairly specilized applications would require raw JMS access.

0

It all depends on your requirements, what frameworks will you use and your applications environment and behavior . If you can give an overview about that then you can get a rigid answer.

It's now like comparing a truck with a sedan car, You must know what will you use it for and on which road to be able decide which one is better.

0

JMS and WS both enable distribute applications. The difference is asynchronous(JMS) vs synchronous (Web Services). Web Services can be implemented in SOAP or REST styles. JMS is a api which supports communication in two modes - point-to-point and publish-subscribe. Apache ActiveMQ, RabitMQ are some of the many JMS implementors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.