use of com.jeesuite.amqp.MQMessage in project jeesuite-libs by vakinge.
the class CMQConsumerAdapter method handleMessageConsumed.
@Override
public String handleMessageConsumed(MQMessage message) {
try {
Message originMessage = message.getOriginMessage(Message.class);
String receiptHandle = originMessage.receiptHandle;
CMQManager.getQueue().deleteMessage(receiptHandle);
} catch (Exception e) {
logger.error("", e);
}
return null;
}
use of com.jeesuite.amqp.MQMessage in project jeesuite-libs by vakinge.
the class RocketProducerAdapter method sendMessage.
@Override
public String sendMessage(MQMessage message, boolean async) {
Message _message = new Message(message.getTopic(), message.getTag(), message.getBizKey(), message.bodyAsBytes());
if (StringUtils.isNotBlank(message.getProduceBy())) {
_message.putUserProperty(MessageHeaderNames.produceBy.name(), message.getProduceBy());
}
if (StringUtils.isNotBlank(message.getRequestId())) {
_message.putUserProperty(MessageHeaderNames.requestId.name(), message.getRequestId());
}
if (StringUtils.isNotBlank(message.getTenantId())) {
_message.putUserProperty(MessageHeaderNames.tenantId.name(), message.getTenantId());
}
if (StringUtils.isNotBlank(message.getCheckUrl())) {
_message.putUserProperty(MessageHeaderNames.checkUrl.name(), message.getProduceBy());
}
if (StringUtils.isNotBlank(message.getTransactionId())) {
_message.putUserProperty(MessageHeaderNames.transactionId.name(), message.getTransactionId());
}
try {
if (async) {
producer.send(_message, new SendCallback() {
@Override
public void onSuccess(SendResult sendResult) {
if (logger.isDebugEnabled())
logger.debug("MQ_SEND_SUCCESS:{} -> msgId:{},status:{},offset:{}", message.getTopic(), sendResult.getMsgId(), sendResult.getSendStatus().name(), sendResult.getQueueOffset());
message.setMsgId(sendResult.getMsgId());
handleSuccess(message);
}
@Override
public void onException(Throwable e) {
handleError(message, e);
logger.warn("MQ_SEND_FAIL:" + message.getTopic(), e);
}
});
} else {
SendResult sendResult = producer.send(_message);
message.setMsgId(sendResult.getMsgId());
if (sendResult.getSendStatus() == SendStatus.SEND_OK) {
handleSuccess(message);
} else {
handleError(message, new MQClientException(0, sendResult.getSendStatus().name()));
}
}
} catch (Exception e) {
handleError(message, e);
logger.warn("MQ_SEND_FAIL:" + message.getTopic(), e);
}
return null;
}
use of com.jeesuite.amqp.MQMessage in project jeesuite-libs by vakinge.
the class KafkaConsumerAdapter method fetchMessages.
@Override
public List<MQMessage> fetchMessages() {
// 手动提交offset
trySubmitOffsets();
ConsumerRecords<String, String> records = kafkaConsumer.poll(timeoutDuration);
Iterator<ConsumerRecord<String, String>> iterator = records.iterator();
List<MQMessage> result = new ArrayList<>(records.count());
MQMessage message;
ConsumerRecord<String, String> item;
while (iterator.hasNext()) {
item = iterator.next();
message = new MQMessage(item.topic(), item.value());
message.setOriginMessage(item);
result.add(message);
}
return result;
}
use of com.jeesuite.amqp.MQMessage in project jeesuite-libs by vakinge.
the class MNSProducer method publishMessage.
public String publishMessage(String topicName, Object data) {
CloudTopic topic = getTopic(topicName);
TopicMessage tMessage = new RawTopicMessage();
tMessage.setBaseMessageBody(new MQMessage(topicName, data).toMessageValue(true));
topic.publishMessage(tMessage);
return tMessage.getMessageId();
}
Aggregations