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;
}
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;
}
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");
}
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;
}
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;
}
Aggregations