Java Code Examples for org.apache.rocketmq.client.producer.DefaultMQProducer#setVipChannelEnabled()
The following examples show how to use
org.apache.rocketmq.client.producer.DefaultMQProducer#setVipChannelEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CanalRocketMQProducer.java From canal-1.1.3 with Apache License 2.0 | 6 votes |
@Override public void init(MQProperties rocketMQProperties) { this.mqProperties = rocketMQProperties; RPCHook rpcHook = null; if (rocketMQProperties.getAliyunAccessKey().length() > 0 && rocketMQProperties.getAliyunSecretKey().length() > 0) { SessionCredentials sessionCredentials = new SessionCredentials(); sessionCredentials.setAccessKey(rocketMQProperties.getAliyunAccessKey()); sessionCredentials.setSecretKey(rocketMQProperties.getAliyunSecretKey()); rpcHook = new ClientRPCHook(sessionCredentials); } defaultMQProducer = new DefaultMQProducer(rocketMQProperties.getProducerGroup(), rpcHook); defaultMQProducer.setNamesrvAddr(rocketMQProperties.getServers()); defaultMQProducer.setRetryTimesWhenSendFailed(rocketMQProperties.getRetries()); defaultMQProducer.setVipChannelEnabled(false); logger.info("##Start RocketMQ producer##"); try { defaultMQProducer.start(); } catch (MQClientException ex) { throw new CanalServerException("Start RocketMQ producer error", ex); } }
Example 2
Source File: AsyncTraceAppender.java From rocketmq-spring-boot-starter with Apache License 2.0 | 6 votes |
/** * 构造消息类型的轨迹数据发送器 * * @param properties 参数属性 * @throws MQClientException 消息异常 */ public AsyncTraceAppender(Properties properties) throws MQClientException { transDataList = new ArrayList<OnsTraceTransferBean>(); traceProducer = new DefaultMQProducer(); this.traceProducer.setProducerGroup(OnsTraceConstants.groupName); traceProducer.setSendMsgTimeout(5000); traceProducer.setInstanceName(properties.getProperty(OnsTraceConstants.InstanceName, String.valueOf(System.currentTimeMillis()))); String nameSrv = properties.getProperty(OnsTraceConstants.NAMESRV_ADDR); if (nameSrv == null) { TopAddressing topAddressing = new TopAddressing(properties.getProperty(OnsTraceConstants.ADDRSRV_URL)); nameSrv = topAddressing.fetchNSAddr(); } traceProducer.setNamesrvAddr(nameSrv); traceProducer.setVipChannelEnabled(false); // 消息最大大小128K int maxSize = Integer.parseInt(properties.getProperty(OnsTraceConstants.MaxMsgSize, "128000")); batchSize = Integer.parseInt(properties.getProperty(OnsTraceConstants.MaxBatchNum, "1")); traceProducer.setMaxMessageSize(maxSize - 10 * 1000); traceProducer.start(); }
Example 3
Source File: RocketmqOfflineInfoHelper.java From netty-chat with Apache License 2.0 | 5 votes |
public RocketmqOfflineInfoHelper() { producer = new DefaultMQProducer("send"); producer.setNamesrvAddr("localhost:9876"); producer.setVipChannelEnabled(false); try { producer.start(); } catch (MQClientException e) { e.printStackTrace(); } }
Example 4
Source File: DeFiBusProducer.java From DeFiBus with Apache License 2.0 | 5 votes |
public DeFiBusProducer(DeFiBusClientConfig deFiBusClientConfig) { RPCHook rpcHookForAuth = DeFiBusClientHookFactory.createRPCHook(deFiBusClientConfig.getRpcHook()); defaultMQProducer = new DefaultMQProducer(deFiBusClientConfig.getProducerGroup(), rpcHookForAuth); defaultMQProducer.setVipChannelEnabled(false); this.rpcHook = rpcHookForAuth; this.deFiBusClientConfig = deFiBusClientConfig; }
Example 5
Source File: SyncProducer.java From java-tutorial with MIT License | 5 votes |
public static void main(String[] args) throws MQClientException { //声明并初始化一个producer DefaultMQProducer producer = new DefaultMQProducer("SYNC_MQ_GROUP"); //设置NameServer地址,此处应改为实际NameServer地址,多个地址之间用;分隔 producer.setNamesrvAddr(NAMESRVADDR); producer.setInstanceName("SYNC_PRODUCER"); // 设置重试次数,默认2 producer.setRetryTimesWhenSendFailed(3); //大于3.5.3版本要设置为false 否则取不到topic producer.setVipChannelEnabled(false); //设置发送超时时间,默认是3000 producer.setSendMsgTimeout(10000); //调用start()方法启动一个producer实例 producer.start(); producer.setRetryTimesWhenSendAsyncFailed(0); System.out.println("producer start"); for (int i = 0; i < 10; i++) { try { Message msg = new Message("Sync_TopicA_Test", "Sync_TagA", ("RocketMQ message " + i).getBytes(RemotingHelper.DEFAULT_CHARSET) ); //发送消息 SendResult sendResult = producer.send(msg); System.out.printf("%s%n", sendResult); } catch (Exception e) { e.printStackTrace(); } } //发送完消息之后,调用shutdown()方法关闭producer producer.shutdown(); System.out.println("producer shutdown"); }
Example 6
Source File: AsyncProducer.java From java-tutorial with MIT License | 5 votes |
public static void main(String[] args) throws Exception { //Instantiate with a producer group name. DefaultMQProducer producer = new DefaultMQProducer("ASYNC_MQ_GROUP"); // Specify name server addresses. producer.setNamesrvAddr(SyncProducer.NAMESRVADDR); producer.setInstanceName("ASYNC_PRODUCER"); producer.setVipChannelEnabled(false); // 设置重试次数,默认2 producer.setRetryTimesWhenSendFailed(3); //设置发送超时时间,默认是3000 producer.setSendMsgTimeout(10000); //Launch the instance. producer.start(); producer.setRetryTimesWhenSendAsyncFailed(0); for (int i = 0; i < 10; i++) { final int index = i; Message msg = new Message("Async_Topic_Test", "Async_TagA", "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); producer.send(msg, new SendCallback() { @Override public void onSuccess(SendResult sendResult) { System.out.printf("%-10d OK %s %n", index, sendResult.getMsgId()); } @Override public void onException(Throwable e) { System.out.printf("%-10d Exception %s %n", index, e); e.printStackTrace(); } }, 10000); } //Shut down once the producer instance is not longer in use. producer.shutdown(); }