You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by moraleslos <mo...@hotmail.com> on 2007/01/19 23:05:10 UTC
sendSync() working like async issue
I'm running into an issue where a consumer component sendSyncs to a provider
component in the same SU but finishes up before the provider finishes its
task. Currently I have a consumer component that reads a file and sendSyncs
the inputStream to the provider component for unmarshaling and persisting.
After running some tests on the same set of 100 files, I can see the
consumer sending 100 files consistently, but the provider component seems to
not receive all of these files, and they vary in the number. It looks like
the consumer component is getting the ExchangeStatus = DONE and closing the
inputStream before the provider component unmarshals/persists. My consumer
and provider snippets are shown below.
*******************************
Consumer component
int count = 0;
...
InputStream is = new FileInputStream(file);
String path = file.getPath();
InOnly inOnlyExchange = getExchangeFactory().createInOnlyExchange();
log.debug("1: InOnlyExchange status = " + inOnlyExchange.getStatus());
NormalizedMessage messageToSend = inOnlyExchange.createMessage();
inOnlyExchange.setInMessage(messageToSend);
marshaler.readMessage(inOnlyExchange, messageToSend, is, path);
log.debug("sending message, count = " + count);
getDeliveryChannel().sendSync(inOnlyExchange);
log.debug("2: InOnlyExchange status = " + inOnlyExchange.getStatus());
is.close();
...
Provider component
int count = 0;
...
protected void process(MessageExchange exchange,NormalizedMessage message)
throws Exception {
log.debug("received message, count = " + count);
Source s = message.getContent();
StreamSource ss = (StreamSource)s;
Book book = (Book) unmarshaller.unmarshal(ss);
bookDao.store(book);
count++;
log.debug("Complete persistence: count = " + count);
done(exchange);
}
*****************************
Below is a sample output:
*******************************
1: InOnlyExchange status = Active
sending message, count = 0
received message, count = 0
2: InOnlyExchange status = Done
1: InOnlyExchange status = Active
sending message, count = 1
received message, count = 0
2: InOnlyExchange status = Done
1: InOnlyExchange status = Active
sending message, count = 2
received message, count = 0
2: InOnlyExchange status = Done
1: InOnlyExchange status = Active
sending message, count = 3
received message, count = 0
2: InOnlyExchange status = Done
Complete persistence: count = 0
...
*******************************
Notice that the consumer completes the sendSync() before anything happens in
the provider. I though that sendSync() would block until the provider
finishes everything. I would expect an output like this:
*****************************
1: InOnlyExchange status = Active
sending message, count = 0
received message, count = 0
Complete persistence: count = 0
2: InOnlyExchange status = Done
1: InOnlyExchange status = Active
sending message, count = 1
received message, count = 1
Complete persistence: count = 1
2: InOnlyExchange status = Done
.....
*****************************
Although the provider is able to receive/unmarshal/persist most of the files
it gets, it does not do it all. Each time I run a test, the number of file
contents persisted is different. I always expect it to be 100.
Any ideas on what I'm doing wrong (I'm using SMX 3.1)? Thanks in advance!
-los
--
View this message in context: http://www.nabble.com/sendSync%28%29-working-like-async-issue-tf3042820s12049.html#a8458122
Sent from the ServiceMix - User mailing list archive at Nabble.com.