Search in sources :

Example 6 with SessionCredentials

use of org.apache.rocketmq.acl.common.SessionCredentials in project rocketmq-externals by apache.

the class Utils method startTargetMQAdminTool.

public static DefaultMQAdminExt startTargetMQAdminTool(RmqConnectorConfig replicatorConfig) throws MQClientException {
    RPCHook rpcHook = null;
    if (replicatorConfig.isTargetAclEnable()) {
        rpcHook = new AclClientRPCHook(new SessionCredentials(replicatorConfig.getTargetAccessKey(), replicatorConfig.getTargetSecretKey()));
    }
    DefaultMQAdminExt targetMQAdminExt = new DefaultMQAdminExt(rpcHook);
    targetMQAdminExt.setNamesrvAddr(replicatorConfig.getTargetNamesrvs());
    targetMQAdminExt.setAdminExtGroup(ConstDefine.REPLICATOR_ADMIN_GROUP);
    targetMQAdminExt.setInstanceName(Utils.createUniqIntanceName(replicatorConfig.getTargetNamesrvs()));
    targetMQAdminExt.start();
    log.info("TARGET: RocketMQ targetMQAdminExt started.");
    return targetMQAdminExt;
}
Also used : SessionCredentials(org.apache.rocketmq.acl.common.SessionCredentials) RPCHook(org.apache.rocketmq.remoting.RPCHook) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook)

Example 7 with SessionCredentials

use of org.apache.rocketmq.acl.common.SessionCredentials in project rocketmq-externals by apache.

the class ConnectUtil method initDefaultMQPullConsumer.

public static DefaultMQPullConsumer initDefaultMQPullConsumer(ConnectConfig connectConfig) {
    RPCHook rpcHook = null;
    if (connectConfig.getAclEnable()) {
        rpcHook = new AclClientRPCHook(new SessionCredentials(connectConfig.getAccessKey(), connectConfig.getSecretKey()));
    }
    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(rpcHook);
    consumer.setNamesrvAddr(connectConfig.getNamesrvAddr());
    consumer.setInstanceName(createUniqInstance(connectConfig.getNamesrvAddr()));
    consumer.setConsumerGroup(connectConfig.getRmqConsumerGroup());
    consumer.setMaxReconsumeTimes(connectConfig.getRmqMaxRedeliveryTimes());
    consumer.setBrokerSuspendMaxTimeMillis(connectConfig.getBrokerSuspendMaxTimeMillis());
    consumer.setConsumerPullTimeoutMillis((long) connectConfig.getRmqMessageConsumeTimeout());
    consumer.setLanguage(LanguageCode.JAVA);
    return consumer;
}
Also used : SessionCredentials(org.apache.rocketmq.acl.common.SessionCredentials) RPCHook(org.apache.rocketmq.remoting.RPCHook) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook) DefaultMQPullConsumer(org.apache.rocketmq.client.consumer.DefaultMQPullConsumer)

Example 8 with SessionCredentials

use of org.apache.rocketmq.acl.common.SessionCredentials in project rocketmq-externals by apache.

the class ConnectUtil method startMQAdminTool.

public static DefaultMQAdminExt startMQAdminTool(ConnectConfig connectConfig) throws MQClientException {
    RPCHook rpcHook = null;
    if (connectConfig.getAclEnable()) {
        rpcHook = new AclClientRPCHook(new SessionCredentials(connectConfig.getAccessKey(), connectConfig.getSecretKey()));
    }
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setNamesrvAddr(connectConfig.getNamesrvAddr());
    defaultMQAdminExt.setAdminExtGroup(connectConfig.getAdminExtGroup());
    defaultMQAdminExt.setInstanceName(ConnectUtil.createUniqInstance(connectConfig.getNamesrvAddr()));
    defaultMQAdminExt.start();
    return defaultMQAdminExt;
}
Also used : SessionCredentials(org.apache.rocketmq.acl.common.SessionCredentials) RPCHook(org.apache.rocketmq.remoting.RPCHook) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook)

Example 9 with SessionCredentials

use of org.apache.rocketmq.acl.common.SessionCredentials in project canal by alibaba.

the class CanalRocketMQConsumer method connect.

@Override
public void connect() {
    RPCHook rpcHook = null;
    if (null != accessKey && accessKey.length() > 0 && null != secretKey && secretKey.length() > 0) {
        SessionCredentials sessionCredentials = new SessionCredentials();
        sessionCredentials.setAccessKey(accessKey);
        sessionCredentials.setSecretKey(secretKey);
        rpcHook = new AclClientRPCHook(sessionCredentials);
    }
    rocketMQConsumer = new DefaultMQPushConsumer(groupName, rpcHook, new AllocateMessageQueueAveragely(), enableMessageTrace, customizedTraceTopic);
    rocketMQConsumer.setVipChannelEnabled(false);
    if (CLOUD_ACCESS_CHANNEL.equals(this.accessChannel)) {
        rocketMQConsumer.setAccessChannel(AccessChannel.CLOUD);
    }
    if (!StringUtils.isEmpty(this.namespace)) {
        rocketMQConsumer.setNamespace(this.namespace);
    }
    if (!StringUtils.isBlank(nameServer)) {
        rocketMQConsumer.setNamesrvAddr(nameServer);
    }
    if (batchSize != -1) {
        rocketMQConsumer.setConsumeMessageBatchMaxSize(batchSize);
    }
    try {
        if (rocketMQConsumer == null) {
            this.connect();
        }
        rocketMQConsumer.subscribe(this.topic, this.filter);
        rocketMQConsumer.registerMessageListener((MessageListenerOrderly) (messageExts, context) -> {
            context.setAutoCommit(true);
            boolean isSuccess = process(messageExts);
            if (isSuccess) {
                return ConsumeOrderlyStatus.SUCCESS;
            } else {
                return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
            }
        });
        rocketMQConsumer.start();
    } catch (MQClientException ex) {
        logger.error("Start RocketMQ consumer error", ex);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) DefaultMQPushConsumer(org.apache.rocketmq.client.consumer.DefaultMQPushConsumer) RPCHook(org.apache.rocketmq.remoting.RPCHook) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook) LoggerFactory(org.slf4j.LoggerFactory) MessageExt(org.apache.rocketmq.common.message.MessageExt) MessageUtil(com.alibaba.otter.canal.connector.core.util.MessageUtil) CanalMessageSerializerUtil(com.alibaba.otter.canal.connector.core.util.CanalMessageSerializerUtil) ArrayList(java.util.ArrayList) MQClientException(org.apache.rocketmq.client.exception.MQClientException) CanalConstants(com.alibaba.otter.canal.connector.core.config.CanalConstants) RocketMQConstants(com.alibaba.otter.canal.connector.rocketmq.config.RocketMQConstants) CanalMsgConsumer(com.alibaba.otter.canal.connector.core.spi.CanalMsgConsumer) Properties(java.util.Properties) Logger(org.slf4j.Logger) Message(com.alibaba.otter.canal.protocol.Message) CanalClientException(com.alibaba.otter.canal.protocol.exception.CanalClientException) BlockingQueue(java.util.concurrent.BlockingQueue) SPI(com.alibaba.otter.canal.connector.core.spi.SPI) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) AllocateMessageQueueAveragely(org.apache.rocketmq.client.consumer.rebalance.AllocateMessageQueueAveragely) TimeUnit(java.util.concurrent.TimeUnit) MessageListenerOrderly(org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly) List(java.util.List) SessionCredentials(org.apache.rocketmq.acl.common.SessionCredentials) JSON(com.alibaba.fastjson.JSON) CommonMessage(com.alibaba.otter.canal.connector.core.consumer.CommonMessage) AccessChannel(org.apache.rocketmq.client.AccessChannel) ConsumeOrderlyStatus(org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus) SessionCredentials(org.apache.rocketmq.acl.common.SessionCredentials) AllocateMessageQueueAveragely(org.apache.rocketmq.client.consumer.rebalance.AllocateMessageQueueAveragely) DefaultMQPushConsumer(org.apache.rocketmq.client.consumer.DefaultMQPushConsumer) RPCHook(org.apache.rocketmq.remoting.RPCHook) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 10 with SessionCredentials

use of org.apache.rocketmq.acl.common.SessionCredentials in project canal by alibaba.

the class CanalRocketMQProducer method init.

@Override
public void init(Properties properties) {
    RocketMQProducerConfig rocketMQProperties = new RocketMQProducerConfig();
    this.mqProperties = rocketMQProperties;
    super.init(properties);
    loadRocketMQProperties(properties);
    RPCHook rpcHook = null;
    if (mqProperties.getAliyunAccessKey().length() > 0 && mqProperties.getAliyunSecretKey().length() > 0) {
        SessionCredentials sessionCredentials = new SessionCredentials();
        sessionCredentials.setAccessKey(mqProperties.getAliyunAccessKey());
        sessionCredentials.setSecretKey(mqProperties.getAliyunSecretKey());
        rpcHook = new AclClientRPCHook(sessionCredentials);
    }
    defaultMQProducer = new DefaultMQProducer(rocketMQProperties.getProducerGroup(), rpcHook, rocketMQProperties.isEnableMessageTrace(), rocketMQProperties.getCustomizedTraceTopic());
    if (CLOUD_ACCESS_CHANNEL.equals(rocketMQProperties.getAccessChannel())) {
        defaultMQProducer.setAccessChannel(AccessChannel.CLOUD);
    }
    if (!StringUtils.isEmpty(rocketMQProperties.getNamespace())) {
        defaultMQProducer.setNamespace(rocketMQProperties.getNamespace());
    }
    defaultMQProducer.setNamesrvAddr(rocketMQProperties.getNamesrvAddr());
    defaultMQProducer.setRetryTimesWhenSendFailed(rocketMQProperties.getRetryTimesWhenSendFailed());
    defaultMQProducer.setVipChannelEnabled(rocketMQProperties.isVipChannelEnabled());
    logger.info("##Start RocketMQ producer##");
    try {
        defaultMQProducer.start();
    } catch (MQClientException ex) {
        throw new CanalException("Start RocketMQ producer error", ex);
    }
    int parallelPartitionSendThreadSize = mqProperties.getParallelSendThreadSize();
    sendPartitionExecutor = new ThreadPoolExecutor(parallelPartitionSendThreadSize, parallelPartitionSendThreadSize, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(parallelPartitionSendThreadSize * 2), new NamedThreadFactory("MQ-Parallel-Sender-Partition"), new ThreadPoolExecutor.CallerRunsPolicy());
}
Also used : SessionCredentials(org.apache.rocketmq.acl.common.SessionCredentials) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) NamedThreadFactory(com.alibaba.otter.canal.common.utils.NamedThreadFactory) RocketMQProducerConfig(com.alibaba.otter.canal.connector.rocketmq.config.RocketMQProducerConfig) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) RPCHook(org.apache.rocketmq.remoting.RPCHook) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook) MQClientException(org.apache.rocketmq.client.exception.MQClientException) CanalException(com.alibaba.otter.canal.common.CanalException)

Aggregations

AclClientRPCHook (org.apache.rocketmq.acl.common.AclClientRPCHook)11 SessionCredentials (org.apache.rocketmq.acl.common.SessionCredentials)11 RPCHook (org.apache.rocketmq.remoting.RPCHook)11 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)4 DefaultMQPushConsumer (org.apache.rocketmq.client.consumer.DefaultMQPushConsumer)3 ArrayList (java.util.ArrayList)2 DefaultMQPullConsumer (org.apache.rocketmq.client.consumer.DefaultMQPullConsumer)2 AllocateMessageQueueAveragely (org.apache.rocketmq.client.consumer.rebalance.AllocateMessageQueueAveragely)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)2 JSON (com.alibaba.fastjson.JSON)1 CanalException (com.alibaba.otter.canal.common.CanalException)1 NamedThreadFactory (com.alibaba.otter.canal.common.utils.NamedThreadFactory)1 CanalConstants (com.alibaba.otter.canal.connector.core.config.CanalConstants)1 CommonMessage (com.alibaba.otter.canal.connector.core.consumer.CommonMessage)1 CanalMsgConsumer (com.alibaba.otter.canal.connector.core.spi.CanalMsgConsumer)1 SPI (com.alibaba.otter.canal.connector.core.spi.SPI)1 CanalMessageSerializerUtil (com.alibaba.otter.canal.connector.core.util.CanalMessageSerializerUtil)1 MessageUtil (com.alibaba.otter.canal.connector.core.util.MessageUtil)1 RocketMQConstants (com.alibaba.otter.canal.connector.rocketmq.config.RocketMQConstants)1