SCA Async/Conversational services Part 1: Internals of Tuscany SCA

Paul Parsons
Nov 12, 2010 · 7 min read

Sometime ago I wrote about developing applications with SCA on a JBI-based infrastructure, using simple SCA services for that.

I’m coming back again with two separate SCA blog posts discussing the usage of more complex services, asynchronous and conversational services:

  • In this post, I provide an example client-server project that implements a conversational and asynchronous service in Tuscany SCA, digging into the internals of the implementation for handling these services using Web Services and JMS bindings. I found this information quite difficult to find.
  • The second post looks into the situation where the usage of a Tuscany SCA runtime is not possible in the client side, but we still need a way to make use of these type of services from a more standard web service client. For the specific case of a web service binding, and knowing the internals of Tuscany I will use a standard jax-ws client to consume a Tuscany SCA conversational and asynchronous service.

Both posts use a common example project, a Counter service that notifies to the client each time the count is updated (every second) via an asynchronous callback. The service is conversational and allows clients to stop the count and restart it through separate independent service calls. Also, multiple clients can be run in parallel, each one with its own counter service instance. Version 1.6 of Tuscany SCA is used in this sample.

The source code of the sample counter service for this post can be found here.

SCA asynchronous and conversational service definition

Let’s refresh how to define a service in Tuscany SCA that is both conversational and defines a callback interface for asynchronous calls to the client. Good references for this are the SCA specifications, the Tuscany SCA documentation and the sample projects included in the distribution. However, while I could find several callback projects on the Tuscany SCA samples there are none that exercise conversations.

Below, you find the interface definition of the SCA service in Java for the CounterService (counter-callback-ws-service maven project).

I use the @Callback and @Conversational annotations to define our service. For the @Callback annotation we need also to define the callback interface class. Therefore, for our counter service we have two interfaces, one for the service which implementation is done in the server side, and another one for the callback which implementation is done in the client side.

* The remote service that will be invoked by the client
public interface CounterService {
void startCounting(int maxcount);

void stopCounting();
void restartCounting();

void shutdownCounting();
The Callback interface is as simple as:/**
* The callback interface for {@link CounterService}.
public interface CounterServiceCallback {
void receiveCount(int count, int end);
The server side implementation of the service looks like:/**
* This class implements CounterService and uses a callback.
public class CounterServiceImpl implements CounterService {
protected String conversationID;
* The setter used by the runtime to set the callback reference
* @param counterServiceCallback
public void setMyServiceCallback(CounterServiceCallback counterServiceCallback) {
System.out.println("setCounterServiceCallback on thread "
+ Thread.currentThread());
this.counterServiceCallback = counterServiceCallback;
On the implementation, the @Service SCA annotation is used to identify the SCA service being implemented and the @Scope which specifies a visibility and lifecycle contract an implementation has with the SCA runtime. Possible values of @Scope are STATELESS, REQUEST, CONVERSATIONAL and COMPOSITE. For this specific service we need to use CONVERSATIONAL, instructing Tuscany that conversation state must be kept in order to correlate interactions between a client and the service. For a description of the rest of scopes, refer to the SCA Java Annotations and API reference specification.Last, we use the @Callback annotation to instruct Tuscany SCA where to inject the Callback reference to be used by the service.The server side SCA composite is very similar than the Tuscany SCA official callback-ws-client and you can find it under the "src/main/resources/counterws.composite". The binding used for the sample is a Web Service binding.Tuscany SCA Counter Service ClientOn the client side (counter-callback-ws-client-SCA maven project) we need to define a client interface that makes use of the counter service. To make it simple, the interface has a method that returns the reference to the Counter Service and an additional helper method to get the current count recorded in the client based on the service callbacks. As in the server side, we have to make sure to define the interface as @Conversational and the implementation with @Scope("CONVERSATION") so Tuscany populates the service call with conversation information.Also, to simplify the sample code, the shared interfaces between client and server (i.e. CounterService and CounterServiceCallback) are included in both projects separately. Ideally, these interfaces would be on a separate interfaces library used by both projects./**
* The client component interface.
public interface CounterServiceClient {

public CounterService getCounterService();

public int getCount();

The client composite is as listed below. It defines the reference to the counter Service and the associated callback. The url defined in the callback is used by Tuscany SCA in the client side to start the listening callback web service:targetNamespace="http://counterws"
callbackInterface="" />For the testing, a unit test is setup (, exercising the counter service, callbacks and conversations.Running the counter service sample projectTo run the counter service sample, extract the source code and:
  • Run the server side, executing the script in the counter-callback-ws-service directory. The server component should start and wait for client requests.

  • Nov 8, 2010 4:11:23 PM org.apache.coyote.http11.Http11Protocol start
    INFO: Starting Coyote HTTP/1.1 on http-8086
    Callback server started (press enter to shutdown)
    Nov 8, 2010 4:11:23 PM addServletMapping
    INFO: Added Servlet mapping: http://localhost:8086/CounterServiceComponent
  • Go to the client project, counter-callback-ws-client-SCA and execute the tests with:
  • mvn clean test
  • On the client side you should see how the client starts the counting service, receives the callbacks and how the counting is stopped and later restarted, continuing the count where it was left.

  • Nov 8, 2010 4:11:28 PM addServletMapping
    INFO: Added Servlet mapping: http://localhost:1999/callback
    Starting Count and waiting 5 seconds for counts…
    CounterServiceCallback — — Received Count: 0 out of 30
    CounterServiceCallback — — Received Count: 1 out of 30
    CounterServiceCallback — — Received Count: 2 out of 30
    CounterServiceCallback — — Received Count: 3 out of 30
    CounterServiceCallback — — Received Count: 4 out of 30
    Stopping Count and waiting 5 seconds for no counts…
    Restarting Count and waiting 5 seconds for counts…
    CounterServiceCallback — — Received Count: 5 out of 30
    CounterServiceCallback — — Received Count: 6 out of 30
    CounterServiceCallback — — Received Count: 7 out of 30
    CounterServiceCallback — — Received Count: 8 out of 30
    Stopping the Client Node
    Nov 8, 2010 4:11:44 PM stop
  • On the server side, you should see the client call and the associated conversationID.

  • INFO: Added Servlet mapping: http://jmatute-laptop:8086/CounterServiceComponent
    setMyServiceCallback on thread Thread[Thread-2,5,main]
    ConversationID = d8a05f47–064b-4832–9cca-7ad035bd36ee. Starting count
    Sleeping …
    Sleeping …
    Sleeping …
    Sleeping …
    Sleeping …
    ConversationID = d8a05f47–064b-4832–9cca-7ad035bd36ee. Stopping count
    Sleeping …
    Sleeping …
    Sleeping …
    Sleeping …
    Sleeping …
    ConversationID = d8a05f47–064b-4832–9cca-7ad035bd36ee. Restarting count
    Sleeping …
    Sleeping …
    Sleeping …
    Sleeping …
    Thread interrupted.
Having reached this point, let's look into how Tuscany SCA is handling the conversations and callbacks and how the required information is included in the underling transport bindings (WS or JMS).Internals of conversational and asynchronous services in Tuscany SCATuscany SCA conversational services (i.e. marked with @Conversational) make use of conversation IDs in order to keep track and correctly map multiple invocations associated with a certain conversation.SCA and Tuscany asynchronous services are similar to those defined, for instance, in BPEL where the forward and callback service calls are two complete separate service invocation calls. Therefore, Tuscany also requires additional information to know where the callback needs to be send and optionally provide a application correlation id for the callback call.Summarising, the below table contains the information used by Tuscany SCA for conversation and callback services:Tuscany informationDescriptionconversationIDUUID identifying the current conversation. This is used by Tuscany SCA to associate accordingly the service instance associated to that conversation.callbackLocationThe location of the callback service. This, depending on the binding used might be a URI for Web Service binding or a Queue name for JMS.callbackIDApplication-specified callback ID, that is used by the application to correlate callbacks with the related application state.The above information needs to be mapped to the specific binding and here is where no standarisation exists, making difficult to have interoperable solutions:
  • WebService Binding : for the Web Service binding, WS-Addressing headers are used in order to store the Tuscany SCA conversational/async required information. Below it is shown an example of a Tuscany Web Service conversational and asynchronous/bidrectional invocation:
  • The WS-Addressing Address contains the Callback URI to be used for the callback invocation. This is normally setup by the client to notify the server where to send the callbacks.
  • The WS-Addressing ReferenceParameters contains the other two information fields under specific Tuscany Namespace, the CallbackID and the ConversationID.
  • http://localhost:1999/callback


  • JMS Binding : For JMS, Tuscany SCA uses JMS Message properties to store the required information. A screenshot (see below) of ActiveMQ console shows an Tuscany SCA JMS Message for conversational and async/bidrectional service.
  • CallbackID, scaConversationID and scaCallbackQueue, Tuscany SCA propietary JMS message properties to hold the information.
  • [caption id=”attachment_1185" align=”aligncenter” width=”569" caption=”Tuscany SCA JMS Message”]
  • [/caption]
ConclusionIn this first post I have presented a Tuscany SCA example that covers both conversational and asynchronous scenarios, not currently available in the official Tuscany SCA samples, and looked into the internals of Tuscany SCA used to handle these services. This provides the basis for the next post, where I will be using this information to extend the project code with a non-SCA JAXWS-based web service client as an approach to consume these services without a Tuscany SCA runtime.

The Server labs

The Server Labs Technology Blog

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store