org.apache.rocketmq.logappender.common.ProducerInstance Java Examples

The following examples show how to use org.apache.rocketmq.logappender.common.ProducerInstance. 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: RocketmqLogbackAppender.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public synchronized void stop() {
    // The synchronized modifier avoids concurrent append and close operations
    if (!this.started) {
        return;
    }

    this.started = false;

    try {
        ProducerInstance.removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        addError("Closeing RocketmqLogbackAppender [" + this.getName()
                + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }

    // Help garbage collection
    producer = null;
}
 
Example #2
Source File: RocketmqLog4j2Appender.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public boolean stop(long timeout, TimeUnit timeUnit) {
    this.setStopping();
    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        ErrorHandler handler = this.getHandler();
        if (handler != null) {
            handler.error("Closeing RocketmqLog4j2Appender [" + this.getName()
                + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
        }
    }

    boolean stopped = super.stop(timeout, timeUnit, false);
    this.setStopped();
    return stopped;
}
 
Example #3
Source File: RocketmqLogbackAppender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
/**
 * Info,error,warn,callback method implementation
 */
@Override
protected void append(ILoggingEvent event) {
    if (!isStarted()) {
        return;
    }
    String logStr = this.layout.doLayout(event);
    try {
        Message msg = new Message(topic, tag, logStr.getBytes());
        msg.getProperties().put(ProducerInstance.APPENDER_TYPE, ProducerInstance.LOGBACK_APPENDER);

        //Send message and do not wait for the ack from the message broker.
        producer.sendOneway(msg);
    } catch (Exception e) {
        addError("Could not send message in RocketmqLogbackAppender [" + name + "]. Message is : " + logStr, e);
    }
}
 
Example #4
Source File: RocketmqLogbackAppender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
/**
 * Options are activated and become effective only after calling this method.
 */
public void start() {
    int errors = 0;

    if (this.layout == null) {
        addStatus(new ErrorStatus("No layout set for the RocketmqLogbackAppender named \"" + name + "\".", this));
        errors++;
    }

    if (errors > 0 || !checkEntryConditions()) {
        return;
    }
    try {
        producer = ProducerInstance.getProducerInstance().getInstance(nameServerAddress, producerGroup);
    } catch (Exception e) {
        addError("Starting RocketmqLogbackAppender [" + this.getName()
            + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }
    if (producer != null) {
        super.start();
    }
}
 
Example #5
Source File: RocketmqLogbackAppender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public synchronized void stop() {
    // The synchronized modifier avoids concurrent append and close operations
    if (!this.started) {
        return;
    }

    this.started = false;

    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        addError("Closeing RocketmqLogbackAppender [" + this.getName()
            + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }

    // Help garbage collection
    producer = null;
}
 
Example #6
Source File: RocketmqLog4jAppender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public synchronized void close() {
    // The synchronized modifier avoids concurrent append and close operations

    if (this.closed)
        return;

    LogLog.debug("Closing RocketmqLog4jAppender [" + name + "].");
    this.closed = true;

    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        LogLog.error("Closing RocketmqLog4jAppender [" + name + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }
    // Help garbage collection
    producer = null;
}
 
Example #7
Source File: RocketmqLog4j2Appender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
protected RocketmqLog4j2Appender(String name, Filter filter, Layout<? extends Serializable> layout,
    boolean ignoreExceptions, String nameServerAddress, String producerGroup,
    String topic, String tag) {
    super(name, filter, layout, ignoreExceptions);
    this.producer = producer;
    this.topic = topic;
    this.tag = tag;
    this.nameServerAddress = nameServerAddress;
    this.producerGroup = producerGroup;
    try {
        this.producer = ProducerInstance.getProducerInstance().getInstance(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        ErrorHandler handler = this.getHandler();
        if (handler != null) {
            handler.error("Starting RocketmqLog4j2Appender [" + this.getName()
                + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
        }
    }
}
 
Example #8
Source File: RocketmqLog4j2Appender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public boolean stop(long timeout, TimeUnit timeUnit) {
    this.setStopping();
    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        ErrorHandler handler = this.getHandler();
        if (handler != null) {
            handler.error("Closeing RocketmqLog4j2Appender [" + this.getName()
                + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
        }
    }

    boolean stopped = super.stop(timeout, timeUnit, false);
    this.setStopped();
    return stopped;
}
 
Example #9
Source File: RocketmqLogbackAppender.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
/**
 * Info,error,warn,callback method implementation
 *
 * @param event
 */
@Override
protected void append(ILoggingEvent event) {
    if (!isStarted()) {
        return;
    }
    String logStr = this.layout.doLayout(event);
    try {
        Message msg = new Message(topic, tag, logStr.getBytes());
        msg.getProperties().put(ProducerInstance.APPENDER_TYPE, ProducerInstance.LOGBACK_APPENDER);

        //Send message and do not wait for the ack from the message broker.
        producer.sendOneway(msg);
    } catch (Exception e) {
        addError("Could not send message in RocketmqLogbackAppender [" + name + "]. Message is : " + logStr, e);
    }
}
 
Example #10
Source File: RocketmqLogbackAppender.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
/**
 * Options are activated and become effective only after calling this method.
 */
public void start() {
    int errors = 0;

    if (this.layout == null) {
        addStatus(new ErrorStatus("No layout set for the RocketmqLogbackAppender named \"" + name + "\".", this));
        errors++;
    }

    if (errors > 0 || !checkEntryConditions()) {
        return;
    }
    try {
        producer = ProducerInstance.getInstance(nameServerAddress, producerGroup);
    } catch (Exception e) {
        addError("Starting RocketmqLogbackAppender [" + this.getName()
                + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }
    if (producer != null) {
        super.start();
    }
}
 
Example #11
Source File: RocketmqLogbackAppender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
/**
 * Info,error,warn,callback method implementation
 */
@Override
protected void append(ILoggingEvent event) {
    if (!isStarted()) {
        return;
    }
    String logStr = this.layout.doLayout(event);
    try {
        Message msg = new Message(topic, tag, logStr.getBytes());
        msg.getProperties().put(ProducerInstance.APPENDER_TYPE, ProducerInstance.LOGBACK_APPENDER);

        //Send message and do not wait for the ack from the message broker.
        producer.sendOneway(msg);
    } catch (Exception e) {
        addError("Could not send message in RocketmqLogbackAppender [" + name + "]. Message is : " + logStr, e);
    }
}
 
Example #12
Source File: RocketmqLog4jAppender.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public synchronized void close() {
    // The synchronized modifier avoids concurrent append and close operations

    if (this.closed)
        return;

    LogLog.debug("Closing RocketmqLog4jAppender [" + name + "].");
    this.closed = true;

    try {
        ProducerInstance.removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        LogLog.error("Closing RocketmqLog4jAppender [" + name + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }
    // Help garbage collection
    producer = null;
}
 
Example #13
Source File: RocketmqLog4j2Appender.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
protected RocketmqLog4j2Appender(String name, Filter filter, Layout<? extends Serializable> layout,
                                 boolean ignoreExceptions, String nameServerAddress, String producerGroup,
                                 String topic, String tag) {
    super(name, filter, layout, ignoreExceptions);
    this.producer = producer;
    this.topic = topic;
    this.tag = tag;
    this.nameServerAddress = nameServerAddress;
    this.producerGroup = producerGroup;
    try {
        this.producer = ProducerInstance.getInstance(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        ErrorHandler handler = this.getHandler();
        if (handler != null) {
            handler.error("Starting RocketmqLog4j2Appender [" + this.getName()
                    + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
        }
    }
}
 
Example #14
Source File: RocketmqLog4j2Appender.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 *
 * @param timeout
 * @param timeUnit
 * @return
 */
public boolean stop(long timeout, TimeUnit timeUnit) {
    this.setStopping();
    try {
        ProducerInstance.removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        ErrorHandler handler = this.getHandler();
        if (handler != null) {
            handler.error("Closeing RocketmqLog4j2Appender [" + this.getName()
                    + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
        }
    }

    boolean stopped = super.stop(timeout, timeUnit, false);
    this.setStopped();
    return stopped;
}
 
Example #15
Source File: RocketmqLogbackAppender.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
/**
 * Info,error,warn,callback method implementation
 */
@Override
protected void append(ILoggingEvent event) {
    if (!isStarted()) {
        return;
    }
    String logStr = this.layout.doLayout(event);
    try {
        Message msg = new Message(topic, tag, logStr.getBytes());
        msg.getProperties().put(ProducerInstance.APPENDER_TYPE, ProducerInstance.LOGBACK_APPENDER);

        //Send message and do not wait for the ack from the message broker.
        producer.sendOneway(msg);
    } catch (Exception e) {
        addError("Could not send message in RocketmqLogbackAppender [" + name + "]. Message is : " + logStr, e);
    }
}
 
Example #16
Source File: RocketmqLogbackAppender.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
/**
 * Options are activated and become effective only after calling this method.
 */
public void start() {
    int errors = 0;

    if (this.layout == null) {
        addStatus(new ErrorStatus("No layout set for the RocketmqLogbackAppender named \"" + name + "\".", this));
        errors++;
    }

    if (errors > 0 || !checkEntryConditions()) {
        return;
    }
    try {
        producer = ProducerInstance.getProducerInstance().getInstance(nameServerAddress, producerGroup);
    } catch (Exception e) {
        addError("Starting RocketmqLogbackAppender [" + this.getName()
            + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }
    if (producer != null) {
        super.start();
    }
}
 
Example #17
Source File: RocketmqLogbackAppender.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public synchronized void stop() {
    // The synchronized modifier avoids concurrent append and close operations
    if (!this.started) {
        return;
    }

    this.started = false;

    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        addError("Closeing RocketmqLogbackAppender [" + this.getName()
            + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }

    // Help garbage collection
    producer = null;
}
 
Example #18
Source File: RocketmqLog4jAppender.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public synchronized void close() {
    // The synchronized modifier avoids concurrent append and close operations

    if (this.closed)
        return;

    LogLog.debug("Closing RocketmqLog4jAppender [" + name + "].");
    this.closed = true;

    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        LogLog.error("Closing RocketmqLog4jAppender [" + name + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }
    // Help garbage collection
    producer = null;
}
 
Example #19
Source File: RocketmqLog4j2Appender.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
protected RocketmqLog4j2Appender(String name, Filter filter, Layout<? extends Serializable> layout,
    boolean ignoreExceptions, String nameServerAddress, String producerGroup,
    String topic, String tag) {
    super(name, filter, layout, ignoreExceptions);
    this.producer = producer;
    this.topic = topic;
    this.tag = tag;
    this.nameServerAddress = nameServerAddress;
    this.producerGroup = producerGroup;
    try {
        this.producer = ProducerInstance.getProducerInstance().getInstance(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        ErrorHandler handler = this.getHandler();
        if (handler != null) {
            handler.error("Starting RocketmqLog4j2Appender [" + this.getName()
                + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
        }
    }
}
 
Example #20
Source File: RocketmqLog4j2Appender.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public boolean stop(long timeout, TimeUnit timeUnit) {
    this.setStopping();
    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        ErrorHandler handler = this.getHandler();
        if (handler != null) {
            handler.error("Closeing RocketmqLog4j2Appender [" + this.getName()
                + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
        }
    }

    boolean stopped = super.stop(timeout, timeUnit, false);
    this.setStopped();
    return stopped;
}
 
Example #21
Source File: RocketmqLog4jAppender.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public synchronized void close() {
    // The synchronized modifier avoids concurrent append and close operations

    if (this.closed)
        return;

    LogLog.debug("Closing RocketmqLog4jAppender [" + name + "].");
    this.closed = true;

    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        LogLog.error("Closing RocketmqLog4jAppender [" + name + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }
    // Help garbage collection
    producer = null;
}
 
Example #22
Source File: RocketmqLogbackAppender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
/**
 * Options are activated and become effective only after calling this method.
 */
public void start() {
    int errors = 0;

    if (this.layout == null) {
        addStatus(new ErrorStatus("No layout set for the RocketmqLogbackAppender named \"" + name + "\".", this));
        errors++;
    }

    if (errors > 0 || !checkEntryConditions()) {
        return;
    }
    try {
        producer = ProducerInstance.getProducerInstance().getInstance(nameServerAddress, producerGroup);
    } catch (Exception e) {
        addError("Starting RocketmqLogbackAppender [" + this.getName()
            + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }
    if (producer != null) {
        super.start();
    }
}
 
Example #23
Source File: RocketmqLogbackAppender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public synchronized void stop() {
    // The synchronized modifier avoids concurrent append and close operations
    if (!this.started) {
        return;
    }

    this.started = false;

    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        addError("Closeing RocketmqLogbackAppender [" + this.getName()
            + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }

    // Help garbage collection
    producer = null;
}
 
Example #24
Source File: RocketmqLog4jAppender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public synchronized void close() {
    // The synchronized modifier avoids concurrent append and close operations

    if (this.closed)
        return;

    LogLog.debug("Closing RocketmqLog4jAppender [" + name + "].");
    this.closed = true;

    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        LogLog.error("Closing RocketmqLog4jAppender [" + name + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }
    // Help garbage collection
    producer = null;
}
 
Example #25
Source File: RocketmqLog4j2Appender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
protected RocketmqLog4j2Appender(String name, Filter filter, Layout<? extends Serializable> layout,
    boolean ignoreExceptions, String nameServerAddress, String producerGroup,
    String topic, String tag) {
    super(name, filter, layout, ignoreExceptions);
    this.producer = producer;
    this.topic = topic;
    this.tag = tag;
    this.nameServerAddress = nameServerAddress;
    this.producerGroup = producerGroup;
    try {
        this.producer = ProducerInstance.getProducerInstance().getInstance(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        ErrorHandler handler = this.getHandler();
        if (handler != null) {
            handler.error("Starting RocketmqLog4j2Appender [" + this.getName()
                + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
        }
    }
}
 
Example #26
Source File: RocketmqLog4j2Appender.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources
 */
public boolean stop(long timeout, TimeUnit timeUnit) {
    this.setStopping();
    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        ErrorHandler handler = this.getHandler();
        if (handler != null) {
            handler.error("Closeing RocketmqLog4j2Appender [" + this.getName()
                + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
        }
    }

    boolean stopped = super.stop(timeout, timeUnit, false);
    this.setStopped();
    return stopped;
}
 
Example #27
Source File: RocketmqLogbackAppender.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
/**
 * Info,error,warn,callback method implementation
 */
@Override
protected void append(ILoggingEvent event) {
    if (!isStarted()) {
        return;
    }
    String logStr = this.layout.doLayout(event);
    try {
        Message msg = new Message(topic, tag, logStr.getBytes());
        msg.getProperties().put(ProducerInstance.APPENDER_TYPE, ProducerInstance.LOGBACK_APPENDER);

        //Send message and do not wait for the ack from the message broker.
        producer.sendOneway(msg);
    } catch (Exception e) {
        addError("Could not send message in RocketmqLogbackAppender [" + name + "]. Message is : " + logStr, e);
    }
}
 
Example #28
Source File: RocketmqLogbackAppender.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
/**
 * Options are activated and become effective only after calling this method.只有在调用此方法后,选项才会被激活并生效。
 */
public void start() {
    int errors = 0;

    if (this.layout == null) {
        addStatus(new ErrorStatus("No layout set for the RocketmqLogbackAppender named \"" + name + "\".", this));
        errors++;
    }

    if (errors > 0 || !checkEntryConditions()) {
        return;
    }
    try {
        producer = ProducerInstance.getProducerInstance().getInstance(nameServerAddress, producerGroup);
    } catch (Exception e) {
        addError("Starting RocketmqLogbackAppender [" + this.getName()
            + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }
    if (producer != null) {
        super.start();
    }
}
 
Example #29
Source File: RocketmqLogbackAppender.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources 当系统退出时,将调用此方法来关闭资源
 */
public synchronized void stop() {
    // The synchronized modifier avoids concurrent append and close operations
    if (!this.started) {
        return;
    }

    this.started = false;

    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        addError("Closeing RocketmqLogbackAppender [" + this.getName()
            + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }

    // Help garbage collection
    producer = null;
}
 
Example #30
Source File: RocketmqLog4jAppender.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
/**
 * When system exit,this method will be called to close resources 当系统退出时,将调用此方法来关闭资源
 */
public synchronized void close() {
    // The synchronized modifier avoids concurrent append and close operations

    if (this.closed)
        return;

    LogLog.debug("Closing RocketmqLog4jAppender [" + name + "].");
    this.closed = true;

    try {
        ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup);
    } catch (Exception e) {
        LogLog.error("Closing RocketmqLog4jAppender [" + name + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
    }
    // Help garbage collection
    producer = null;
}