public void sendMessages(int messageCount) throws JBIException {
sendMessages(messageCount, false);
}
public void sendMessages(int messageCount, boolean sync) throws JBIException {
ComponentContext context = getContext();
for (int i = 0; i < messageCount; i++) {
InOnly exchange = context.getDeliveryChannel().createExchangeFactory().createInOnlyExchange();
NormalizedMessage msg = exchange.createMessage();
ServiceEndpoint destination = null;
if (resolver != null) {
destination = resolver.resolveEndpoint(getContext(), exchange, NullEndpointFilter.getInstance());
}
if (destination != null) {
// lets explicitly specify the destination - otherwise
// we'll let the container choose for us
exchange.setEndpoint(destination);
}
exchange.setInMessage(msg);
// lets set the XML as a byte[], String or DOM etc
msg.setContent(new StringSource(this.message));
if (sync) {
boolean result = context.getDeliveryChannel().sendSync(exchange, 1000);
if (!result) {
throw new MessagingException("Message delivery using sendSync has timed out");
}
} else {
context.getDeliveryChannel().send(exchange);
}
}
}