Search in sources :

Example 1 with MessageEntity

use of com.yanghui.elephant.store.entity.MessageEntity in project elephant by yanghuijava.

the class RetrySendMQJob method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(ShardingContext shardingContext) {
    List<MessageEntity> findList = this.messageEntityMapper.querySendMQExcetion();
    log.info("查询消息确认但是发送mq失败的(查询1分钟之前的)记录数:{}", findList);
    if (findList.isEmpty()) {
        return;
    }
    for (MessageEntity find : findList) {
        Message message = new Message();
        message.setMessageId(find.getMessageId());
        message.setBody(find.getBody());
        message.setDestination(find.getDestination());
        if (!StringUtils.isEmpty(find.getProperties())) {
            message.setProperties(JSON.parseObject(find.getProperties(), Map.class));
        }
        this.producerService.sendMessage(message);
        MessageEntity update = new MessageEntity();
        update.setMessageId(find.getMessageId());
        update.setSendStatus(SendStatus.ALREADY_SEND.getStatus());
        update.setUpdateTime(new Date());
        this.messageEntityMapper.updateByMessageId(update);
    }
}
Also used : MessageEntity(com.yanghui.elephant.store.entity.MessageEntity) Message(com.yanghui.elephant.common.message.Message) Map(java.util.Map) Date(java.util.Date)

Example 2 with MessageEntity

use of com.yanghui.elephant.store.entity.MessageEntity in project elephant by yanghuijava.

the class AbstractRequestProcessor method handleTransactionState.

@SuppressWarnings("unchecked")
protected void handleTransactionState(String messageId, String commitOrRollback) {
    LocalTransactionState localState = LocalTransactionState.valueOfName(commitOrRollback);
    MessageEntity findMessageEntity = this.messageEntityManager.findByMessageId(messageId);
    boolean sendMq = false;
    switch(localState) {
        case COMMIT_MESSAGE:
            this.messageEntityManager.updateStatusByMessageId(MessageStatus.CONFIRMED.getStatus(), findMessageEntity.getMessageId());
            sendMq = true;
            break;
        case ROLLBACK_MESSAGE:
            this.messageEntityManager.updateStatusByMessageId(MessageStatus.ROLLBACK.getStatus(), findMessageEntity.getMessageId());
            break;
        default:
            break;
    }
    if (sendMq) {
        Message message = new Message();
        message.setBody(findMessageEntity.getBody());
        message.setDestination(findMessageEntity.getDestination());
        message.setMessageId(findMessageEntity.getMessageId());
        if (!StringUtil.isEmpty(findMessageEntity.getProperties())) {
            message.setProperties((Map<String, String>) JSON.parseObject(findMessageEntity.getProperties(), Map.class));
        }
        this.producerService.sendMessage(message);
        this.messageEntityManager.updateSendStatusByMessageId(SendStatus.ALREADY_SEND.getStatus(), findMessageEntity.getMessageId());
    }
}
Also used : MessageEntity(com.yanghui.elephant.store.entity.MessageEntity) Message(com.yanghui.elephant.common.message.Message) LocalTransactionState(com.yanghui.elephant.common.constant.LocalTransactionState)

Example 3 with MessageEntity

use of com.yanghui.elephant.store.entity.MessageEntity in project elephant by yanghuijava.

the class MessageRequestProcessor method normalMessageHandle.

@SuppressWarnings("unchecked")
private RemotingCommand normalMessageHandle(SendMessageRequestHeader requestHeader, RemotingCommand request) {
    RemotingCommand response = RemotingCommand.buildResposeCmd(ResponseCode.SERVER_FAIL, request.getUnique());
    MessageEntity entity = buildMessageEntity(request.getBody(), requestHeader, false);
    int responseCode = saveMessage(entity);
    if (responseCode != ResponseCode.SUCCESS) {
        response.setCode(responseCode);
        return response;
    }
    Message message = new Message();
    message.setBody(request.getBody());
    message.setDestination(requestHeader.getDestination());
    message.setMessageId(requestHeader.getMessageId());
    if (!StringUtil.isEmpty(requestHeader.getProperties())) {
        message.setProperties((Map<String, String>) JSON.parseObject(requestHeader.getProperties(), Map.class));
    }
    try {
        this.producerService.sendMessage(message);
    } catch (Exception e) {
        log.error("send mq exception:{}", e);
        response.setCode(ResponseCode.SEND_MQ_FAIL);
        return response;
    }
    response.setCode(ResponseCode.SUCCESS);
    try {
        this.messageEntityManager.updateSendStatusByMessageId(SendStatus.ALREADY_SEND.getStatus(), requestHeader.getMessageId());
    } catch (Exception e) {
        log.error("update message status exception:{}", e);
    }
    return response;
}
Also used : RemotingCommand(com.yanghui.elephant.remoting.procotol.RemotingCommand) MessageEntity(com.yanghui.elephant.store.entity.MessageEntity) Message(com.yanghui.elephant.common.message.Message)

Example 4 with MessageEntity

use of com.yanghui.elephant.store.entity.MessageEntity in project elephant by yanghuijava.

the class MessageEntityManagerImpl method findByMessageId.

@Override
public MessageEntity findByMessageId(String messageId) {
    MessageEntity select = new MessageEntity();
    select.setMessageId(messageId);
    MessageEntity find = this.messageEntityMapper.selectOne(select);
    return find;
}
Also used : MessageEntity(com.yanghui.elephant.store.entity.MessageEntity)

Example 5 with MessageEntity

use of com.yanghui.elephant.store.entity.MessageEntity in project elephant by yanghuijava.

the class MessageRequestProcessor method transactionMessageHandle.

private RemotingCommand transactionMessageHandle(SendMessageRequestHeader requestHeader, RemotingCommand request) {
    RemotingCommand response = RemotingCommand.buildResposeCmd(ResponseCode.SERVER_FAIL, request.getUnique());
    MessageEntity entity = buildMessageEntity(request.getBody(), requestHeader, true);
    int responseCode = saveMessage(entity);
    response.setCode(responseCode);
    return response;
}
Also used : RemotingCommand(com.yanghui.elephant.remoting.procotol.RemotingCommand) MessageEntity(com.yanghui.elephant.store.entity.MessageEntity)

Aggregations

MessageEntity (com.yanghui.elephant.store.entity.MessageEntity)9 Date (java.util.Date)4 Message (com.yanghui.elephant.common.message.Message)3 RemotingCommand (com.yanghui.elephant.remoting.procotol.RemotingCommand)3 LocalTransactionState (com.yanghui.elephant.common.constant.LocalTransactionState)1 CheckTransactionStateRequestHeader (com.yanghui.elephant.common.protocol.header.CheckTransactionStateRequestHeader)1 Map (java.util.Map)1