org.apache.rocketmq.client.producer.MQProducer Java Examples

The following examples show how to use org.apache.rocketmq.client.producer.MQProducer. 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: ProducerInstance.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public static MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
    if (group == null) {
        group = DEFAULT_GROUP;
    }

    String genKey = genKey(nameServerAddress, group);
    MQProducer p = producerMap.get(genKey);
    if (p != null) {
        return p;
    }

    DefaultMQProducer defaultMQProducer = new DefaultMQProducer(group);
    defaultMQProducer.setNamesrvAddr(nameServerAddress);
    MQProducer beforeProducer = null;
    //cas put producer
    beforeProducer = producerMap.putIfAbsent(genKey, defaultMQProducer);
    if (beforeProducer != null) {
        return beforeProducer;
    }
    defaultMQProducer.start();
    return defaultMQProducer;
}
 
Example #2
Source File: ProducerInstance.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
    if (StringUtils.isBlank(group)) {
        group = DEFAULT_GROUP;
    }

    String genKey = genKey(nameServerAddress, group);
    MQProducer p = getProducerInstance().producerMap.get(genKey);
    if (p != null) {
        return p;
    }

    DefaultMQProducer defaultMQProducer = new DefaultMQProducer(group);
    defaultMQProducer.setNamesrvAddr(nameServerAddress);
    MQProducer beforeProducer = null;
    beforeProducer = getProducerInstance().producerMap.putIfAbsent(genKey, defaultMQProducer);
    if (beforeProducer != null) {
        return beforeProducer;
    }
    defaultMQProducer.start();
    return defaultMQProducer;
}
 
Example #3
Source File: ProducerInstance.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
    if (StringUtils.isBlank(group)) {
        group = DEFAULT_GROUP;
    }

    String genKey = genKey(nameServerAddress, group);
    MQProducer p = getProducerInstance().producerMap.get(genKey);
    if (p != null) {
        return p;
    }

    DefaultMQProducer defaultMQProducer = new DefaultMQProducer(group);
    defaultMQProducer.setNamesrvAddr(nameServerAddress);
    MQProducer beforeProducer = null;
    beforeProducer = getProducerInstance().producerMap.putIfAbsent(genKey, defaultMQProducer);
    if (beforeProducer != null) {
        return beforeProducer;
    }
    defaultMQProducer.start();
    return defaultMQProducer;
}
 
Example #4
Source File: ProducerInstance.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
    if (StringUtils.isBlank(group)) {
        group = DEFAULT_GROUP;
    }

    String genKey = genKey(nameServerAddress, group);
    MQProducer p = getProducerInstance().producerMap.get(genKey);
    if (p != null) {
        return p;
    }

    DefaultMQProducer defaultMQProducer = new DefaultMQProducer(group);
    defaultMQProducer.setNamesrvAddr(nameServerAddress);
    MQProducer beforeProducer = null;
    beforeProducer = getProducerInstance().producerMap.putIfAbsent(genKey, defaultMQProducer);
    if (beforeProducer != null) {
        return beforeProducer;
    }
    defaultMQProducer.start();
    return defaultMQProducer;
}
 
Example #5
Source File: ProducerInstance.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
    if (StringUtils.isBlank(group)) {
        group = DEFAULT_GROUP;
    }

    String genKey = genKey(nameServerAddress, group);
    MQProducer p = getProducerInstance().producerMap.get(genKey);
    if (p != null) {
        return p;
    }

    DefaultMQProducer defaultMQProducer = new DefaultMQProducer(group);
    defaultMQProducer.setNamesrvAddr(nameServerAddress);
    MQProducer beforeProducer = null;
    beforeProducer = getProducerInstance().producerMap.putIfAbsent(genKey, defaultMQProducer);
    if (beforeProducer != null) {
        return beforeProducer;
    }
    defaultMQProducer.start();
    return defaultMQProducer;
}
 
Example #6
Source File: ProducerInstance.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
    if (StringUtils.isBlank(group)) {
        group = DEFAULT_GROUP;
    }

    String genKey = genKey(nameServerAddress, group);
    MQProducer p = getProducerInstance().producerMap.get(genKey);
    if (p != null) {
        return p;
    }

    DefaultMQProducer defaultMQProducer = new DefaultMQProducer(group);
    defaultMQProducer.setNamesrvAddr(nameServerAddress);
    MQProducer beforeProducer = null;
    beforeProducer = getProducerInstance().producerMap.putIfAbsent(genKey, defaultMQProducer);
    if (beforeProducer != null) {
        return beforeProducer;
    }
    defaultMQProducer.start();
    return defaultMQProducer;
}
 
Example #7
Source File: ProducerInstance.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void removeAndClose(String nameServerAddress, String group) {
    if (group == null) {
        group = DEFAULT_GROUP;
    }
    String genKey = genKey(nameServerAddress, group);
    MQProducer producer = getProducerInstance().producerMap.remove(genKey);

    if (producer != null) {
        producer.shutdown();
    }
}
 
Example #8
Source File: ProducerInstance.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static void removeAndClose(String nameServerAddress, String group) {
    if (group == null) {
        group = DEFAULT_GROUP;
    }
    String genKey = genKey(nameServerAddress, group);
    MQProducer producer = producerMap.remove(genKey);

    if (producer != null) {
        producer.shutdown();
    }
}
 
Example #9
Source File: ProducerInstance.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static void closeAll() {
    Set<Map.Entry<String, MQProducer>> entries = producerMap.entrySet();
    for (Map.Entry<String, MQProducer> entry : entries) {
        producerMap.remove(entry.getKey());
        entry.getValue().shutdown();
    }
}
 
Example #10
Source File: ProducerInstance.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void closeAll() {
    Set<Map.Entry<String, MQProducer>> entries = getProducerInstance().producerMap.entrySet();
    for (Map.Entry<String, MQProducer> entry : entries) {
        getProducerInstance().producerMap.remove(entry.getKey());
        entry.getValue().shutdown();
    }
}
 
Example #11
Source File: ProducerInstance.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void removeAndClose(String nameServerAddress, String group) {
    if (group == null) {
        group = DEFAULT_GROUP;
    }
    String genKey = genKey(nameServerAddress, group);
    MQProducer producer = getProducerInstance().producerMap.remove(genKey);

    if (producer != null) {
        producer.shutdown();
    }
}
 
Example #12
Source File: ProducerInstance.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public void closeAll() {
    Set<Map.Entry<String, MQProducer>> entries = getProducerInstance().producerMap.entrySet();
    for (Map.Entry<String, MQProducer> entry : entries) {
        getProducerInstance().producerMap.remove(entry.getKey());
        entry.getValue().shutdown();
    }
}
 
Example #13
Source File: ProducerInstance.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public void removeAndClose(String nameServerAddress, String group) {
    if (group == null) {
        group = DEFAULT_GROUP;
    }
    String genKey = genKey(nameServerAddress, group);
    MQProducer producer = getProducerInstance().producerMap.remove(genKey);

    if (producer != null) {
        producer.shutdown();
    }
}
 
Example #14
Source File: ProducerInstance.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public void closeAll() {
    Set<Map.Entry<String, MQProducer>> entries = getProducerInstance().producerMap.entrySet();
    for (Map.Entry<String, MQProducer> entry : entries) {
        getProducerInstance().producerMap.remove(entry.getKey());
        entry.getValue().shutdown();
    }
}
 
Example #15
Source File: ProducerInstance.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public void removeAndClose(String nameServerAddress, String group) {
    if (group == null) {
        group = DEFAULT_GROUP;
    }
    String genKey = genKey(nameServerAddress, group);
    MQProducer producer = getProducerInstance().producerMap.remove(genKey);

    if (producer != null) {
        producer.shutdown();
    }
}
 
Example #16
Source File: ProducerInstance.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void closeAll() {
    Set<Map.Entry<String, MQProducer>> entries = getProducerInstance().producerMap.entrySet();
    for (Map.Entry<String, MQProducer> entry : entries) {
        getProducerInstance().producerMap.remove(entry.getKey());
        entry.getValue().shutdown();
    }
}
 
Example #17
Source File: ProducerInstance.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void closeAll() {
    Set<Map.Entry<String, MQProducer>> entries = getProducerInstance().producerMap.entrySet();
    for (Map.Entry<String, MQProducer> entry : entries) {
        getProducerInstance().producerMap.remove(entry.getKey());
        entry.getValue().shutdown();
    }
}
 
Example #18
Source File: ProducerInstance.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void removeAndClose(String nameServerAddress, String group) {
    if (group == null) {
        group = DEFAULT_GROUP;
    }
    String genKey = genKey(nameServerAddress, group);
    MQProducer producer = getProducerInstance().producerMap.remove(genKey);

    if (producer != null) {
        producer.shutdown();
    }
}
 
Example #19
Source File: RocketMQProducerModule.java    From nano-framework with Apache License 2.0 5 votes vote down vote up
private void shutdown() {
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        cfgs.values().forEach(cfg -> {
            final MQProducer producer = cfg.getProducer();
            if (producer != null) {
                try {
                    producer.shutdown();
                } catch (final Throwable e) {
                    LOGGER.error("Shutdown producer error: {}", e.getMessage());
                }
            }
        });
    }));
}
 
Example #20
Source File: RocketMQProducerModule.java    From nano-framework with Apache License 2.0 5 votes vote down vote up
private void bind(final Binder binder) {
    cfgs.forEach((id, cfg) -> {
        final DefaultMQProducer producer = cfg.getProducer();
        if (producer != null) {
            try {
                producer.start();
                binder.bind(MQProducer.class).annotatedWith(Names.named(ROCKETMQ_PREFIX + id)).toInstance(producer);
            } catch (final MQClientException e) {
                producer.shutdown();
                throw new org.nanoframework.orm.rocketmq.exception.MQClientException(e.getErrorMessage(), e);
            }
        }
    });
}
 
Example #21
Source File: SendRocketMQService.java    From enode with MIT License 4 votes vote down vote up
public SendRocketMQService(MQProducer producer) {
    this.producer = producer;
}
 
Example #22
Source File: EnodeRocketMQAutoConfig.java    From enode with MIT License 4 votes vote down vote up
@Bean
public SendRocketMQService sendRocketMQService(@Qualifier(value = "enodeMQProducer") MQProducer mqProducer) {
    return new SendRocketMQService(mqProducer);
}
 
Example #23
Source File: RocketmqLog4jAppender.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the message producer,Only valid after
 * activateOptions() method has been invoked.
 */
protected MQProducer getProducer() {
    return producer;
}
 
Example #24
Source File: RocketmqLog4jAppender.java    From rocketmq with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the message producer,Only valid after
 * activateOptions() method has been invoked.
 */
protected MQProducer getProducer() {
    return producer;
}
 
Example #25
Source File: RocketmqLog4jAppender.java    From DDMQ with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the message producer,Only valid after
 * activateOptions() method has been invoked.
 */
protected MQProducer getProducer() {
    return producer;
}
 
Example #26
Source File: RocketmqLog4jAppender.java    From rocketmq-read with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the message producer,Only valid after
 * activateOptions() method has been invoked.
 */
protected MQProducer getProducer() {
    return producer;
}
 
Example #27
Source File: RocketmqLog4jAppender.java    From rocketmq-4.3.0 with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the message producer,Only valid after
 * activateOptions() method has been invoked.返回消息生成器,只有在调用activateOptions()方法后才有效。
 */
protected MQProducer getProducer() {
    return producer;
}
 
Example #28
Source File: RocketmqLog4jAppender.java    From DDMQ with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the message producer,Only valid after
 * activateOptions() method has been invoked.
 */
protected MQProducer getProducer() {
    return producer;
}