要求:从Oracle AQJMS中获取数据,对其进行处理并将其移交给Cloud流。
添加MessageListener意味着每条消息都将在单独的线程中处理。我需要这些侦听器来连续侦听队列并继续处理数据。
解决方案:以下是代码的症结所在。 问:注册Messagelistener是否意味着每条记录在到达队列时都在单独的线程中处理。
队列wrt是否需要连接池才能实现QueueSession:
需求:我需要实现多队列使用者,它将监听多个JMS队列,处理消息并将它们推送到Cloud。
我为每个需要处理消息的连接队列编写了一个单独的可运行对象。
我的问题是解决此问题的最佳方法是什么。
这里是相关代码,可以进行处理。
public class MultiQueueConsumer implements Runnable {
/*
* private ISubscribeQueue subscribeQueue=SubScribeQueueImpl.INSTANCE; private
* CloudSync cloudSync=AWSCloudSyncImpl.INSTANCE; private DataExtractor
* dataExtractor=DataExtractorImpl.INSTANCE;
*/
private ISubscribeQueue subscribeQueue;
private DataExtractor dataExtractor;
private DataTransformer dataTransformer;
private CloudSync cloudSync;
private String rmobInstance;
@Inject
public MultiQueueConsumer(ISubscribeQueue iSubscribeQueue, CloudSync cloudSync, DataExtractor dataExtractor,
DataTransformer dataTransformer, @Assisted String rmobInstance) {
this.subscribeQueue = iSubscribeQueue;
this.cloudSync = cloudSync;
this.dataExtractor = dataExtractor;
this.rmobInstance = rmobInstance;
}
@Override
public void run() {
Optional<QueueMetaHolder> metaHolder = subscribeQueue.subscribe(rmobInstance);
if (metaHolder.isPresent())
processRecords(metaHolder.get());
}
private void processRecords(QueueMetaHolder metaHolder) {
QueueReceiver queueReceiver = metaHolder.getQueueReceiver();
try {
System.out.println("Listening to queue" + " " + metaHolder.getConnection().getClientID());
} catch (JMSException e1) {
e1.printStackTrace();
}
try {
queueReceiver.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
if (message != null) {
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
long changeId;
try {
changeId = Long.parseLong(textMessage.getText());
message.acknowledge();
McpClusteredDeltaCollection clusteredDeltaCollection = dataExtractor
.getClusteredDataCollection(changeId, rmobInstance);
Optional<PayLoad> payload = dataTransformer
.tranformResultSetToPayLoad(clusteredDeltaCollection);
boolean cloudStreamSyncStatus = cloudSync.syncToStream(payload.get());
boolean cloudSearchServerSyncStatus = cloudSync.syncToSearchServer(payload.get());
} catch (Exception e) {
e.printStackTrace();
}
}
}
else
System.out.println("Nothing recevied from JMS queue" + " " + message);
}
});
// Message message =
// queueReceiver.receive(TimeUnit.MILLISECONDS.toSeconds(2000));
} catch (JMSException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}