use of com.ibm.as400.access.KeyedDataQueue in project camel by apache.
the class Jt400DataQueueService method start.
@Override
public void start() throws Exception {
if (queue == null) {
AS400 system = endpoint.getSystem();
if (endpoint.isKeyed()) {
queue = new KeyedDataQueue(system, endpoint.getObjectPath());
} else {
queue = new DataQueue(system, endpoint.getObjectPath());
}
}
if (!queue.getSystem().isConnected(AS400.DATAQUEUE)) {
LOG.info("Connecting to {}", endpoint);
queue.getSystem().connectService(AS400.DATAQUEUE);
}
}
use of com.ibm.as400.access.KeyedDataQueue in project camel by apache.
the class Jt400DataQueueConsumer method receive.
private Exchange receive(KeyedDataQueue queue, long timeout) throws Exception {
String key = getEndpoint().getSearchKey();
String searchType = getEndpoint().getSearchType().name();
KeyedDataQueueEntry entry;
if (timeout >= 0) {
int seconds = (int) timeout / 1000;
log.trace("Reading from data queue: {} with {} seconds timeout", queue.getName(), seconds);
entry = queue.read(key, seconds, searchType);
} else {
log.trace("Reading from data queue: {} with no timeout", queue.getName());
entry = queue.read(key, -1, searchType);
}
Exchange exchange = getEndpoint().createExchange();
if (entry != null) {
exchange.getIn().setHeader(Jt400Endpoint.SENDER_INFORMATION, entry.getSenderInformation());
if (getEndpoint().getFormat() == Jt400Configuration.Format.binary) {
exchange.getIn().setBody(entry.getData());
exchange.getIn().setHeader(Jt400Endpoint.KEY, entry.getKey());
} else {
exchange.getIn().setBody(entry.getString());
exchange.getIn().setHeader(Jt400Endpoint.KEY, entry.getKeyString());
}
return exchange;
}
return null;
}
Aggregations