Search in sources :

Example 1 with SessionCredentials

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

the class ConnectUtil method initDefaultMQPushConsumer.

public static DefaultMQPushConsumer initDefaultMQPushConsumer(ConnectConfig connectConfig) {
    RPCHook rpcHook = null;
    if (connectConfig.getAclEnable()) {
        rpcHook = new AclClientRPCHook(new SessionCredentials(connectConfig.getAccessKey(), connectConfig.getSecretKey()));
    }
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(rpcHook);
    consumer.setNamesrvAddr(connectConfig.getNamesrvAddr());
    consumer.setInstanceName(createUniqInstance(connectConfig.getNamesrvAddr()));
    consumer.setConsumerGroup(createGroupName(connectConfig.getRmqConsumerGroup()));
    consumer.setMaxReconsumeTimes(connectConfig.getRmqMaxRedeliveryTimes());
    consumer.setConsumeTimeout((long) connectConfig.getRmqMessageConsumeTimeout());
    consumer.setConsumeThreadMin(connectConfig.getRmqMinConsumeThreadNums());
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
    consumer.setLanguage(LanguageCode.JAVA);
    return consumer;
}
Also used : SessionCredentials(org.apache.rocketmq.acl.common.SessionCredentials) 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)

Example 2 with SessionCredentials

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

the class ConnectUtil method initDefaultMQProducer.

public static DefaultMQProducer initDefaultMQProducer(ConnectConfig connectConfig) {
    RPCHook rpcHook = null;
    if (connectConfig.getAclEnable()) {
        rpcHook = new AclClientRPCHook(new SessionCredentials(connectConfig.getAccessKey(), connectConfig.getSecretKey()));
    }
    DefaultMQProducer producer = new DefaultMQProducer(rpcHook);
    producer.setNamesrvAddr(connectConfig.getNamesrvAddr());
    producer.setInstanceName(createUniqInstance(connectConfig.getNamesrvAddr()));
    producer.setProducerGroup(connectConfig.getRmqProducerGroup());
    producer.setSendMsgTimeout(connectConfig.getOperationTimeout());
    producer.setMaxMessageSize(RuntimeConfigDefine.MAX_MESSAGE_SIZE);
    producer.setLanguage(LanguageCode.JAVA);
    return producer;
}
Also used : SessionCredentials(org.apache.rocketmq.acl.common.SessionCredentials) 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)

Example 3 with SessionCredentials

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

the class RmqSourceTask method start.

@Override
public void start(KeyValue config) {
    ConfigUtil.load(config, this.config);
    RPCHook rpcHook = null;
    if (this.config.isSrcAclEnable()) {
        rpcHook = new AclClientRPCHook(new SessionCredentials(this.config.getSrcAccessKey(), this.config.getSrcSecretKey()));
    }
    this.consumer = new DefaultMQPullConsumer(rpcHook);
    this.consumer.setConsumerGroup(this.taskId);
    this.consumer.setNamesrvAddr(this.config.getSourceRocketmq());
    this.consumer.setInstanceName(Utils.createInstanceName(this.config.getSourceRocketmq()));
    List<TaskTopicInfo> topicList = JSONObject.parseArray(this.config.getTaskTopicList(), TaskTopicInfo.class);
    try {
        if (topicList == null) {
            throw new IllegalStateException("topicList is null");
        }
        this.consumer.start();
        List<TaskTopicInfo> topicListFilter = new ArrayList<>();
        for (TaskTopicInfo tti : topicList) {
            Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues(tti.getTopic());
            for (MessageQueue mq : mqs) {
                if (tti.getBrokerName().equals(mq.getBrokerName()) && tti.getQueueId() == mq.getQueueId()) {
                    topicListFilter.add(tti);
                    break;
                }
            }
        }
        PositionStorageReader positionStorageReader = this.context.positionStorageReader();
        mqOffsetMap.putAll(getPositionMapWithCheck(topicListFilter, positionStorageReader, this.TIMEOUT, TimeUnit.MILLISECONDS));
        started = true;
    } catch (Exception e) {
        log.error("Consumer of task {} start failed.", this.taskId, e);
        throw new IllegalStateException(String.format("Consumer of task %s start failed.", this.taskId));
    }
    log.info("RocketMQ source task started");
}
Also used : SessionCredentials(org.apache.rocketmq.acl.common.SessionCredentials) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) PositionStorageReader(io.openmessaging.connector.api.PositionStorageReader) TaskTopicInfo(org.apache.rocketmq.replicator.config.TaskTopicInfo) ArrayList(java.util.ArrayList) 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 4 with SessionCredentials

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

the class Utils method startSrcMQAdminTool.

public static DefaultMQAdminExt startSrcMQAdminTool(RmqConnectorConfig replicatorConfig) throws MQClientException {
    RPCHook rpcHook = null;
    if (replicatorConfig.isSrcAclEnable()) {
        rpcHook = new AclClientRPCHook(new SessionCredentials(replicatorConfig.getSrcAccessKey(), replicatorConfig.getSrcSecretKey()));
    }
    DefaultMQAdminExt srcMQAdminExt = new DefaultMQAdminExt(rpcHook);
    srcMQAdminExt.setNamesrvAddr(replicatorConfig.getSrcNamesrvs());
    srcMQAdminExt.setAdminExtGroup(ConstDefine.REPLICATOR_ADMIN_GROUP);
    srcMQAdminExt.setInstanceName(Utils.createUniqIntanceName(replicatorConfig.getSrcNamesrvs()));
    srcMQAdminExt.start();
    log.info("SOURCE: RocketMQ srcMQAdminExt started");
    return srcMQAdminExt;
}
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 5 with SessionCredentials

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

the class Utils method startMQAdminTool.

public static DefaultMQAdminExt startMQAdminTool(TaskConfig taskConfig) throws MQClientException {
    RPCHook rpcHook = null;
    if (taskConfig.isSrcAclEnable()) {
        rpcHook = new AclClientRPCHook(new SessionCredentials(taskConfig.getSrcAccessKey(), taskConfig.getSrcSecretKey()));
    }
    DefaultMQAdminExt targetMQAdminExt = new DefaultMQAdminExt(rpcHook);
    targetMQAdminExt.setNamesrvAddr(taskConfig.getSourceRocketmq());
    targetMQAdminExt.setAdminExtGroup(ConstDefine.REPLICATOR_TASK_ADMIN_GROUP);
    targetMQAdminExt.setInstanceName(Utils.createUniqIntanceName(taskConfig.getSourceRocketmq()));
    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)

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