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