use of core.framework.impl.log.filter.BytesParam in project core-ng-project by neowu.
the class KafkaMessagePublisher method publish.
@Override
public void publish(String topic, String key, T value) {
if (topic == null)
throw new Error("topic must not be null");
// if key is null, kafka will pick random partition which breaks determinacy
if (key == null)
throw new Error("key must not be null");
validator.validate(value);
StopWatch watch = new StopWatch();
byte[] message = writer.toJSON(value);
try {
ProducerRecord<String, byte[]> record = new ProducerRecord<>(topic, key, message);
Headers headers = record.headers();
headers.add(KafkaHeaders.HEADER_CLIENT_IP, Strings.bytes(Network.localHostAddress()));
if (logManager.appName != null)
headers.add(KafkaHeaders.HEADER_CLIENT, Strings.bytes(logManager.appName));
linkContext(headers);
producer.send(record);
} finally {
long elapsedTime = watch.elapsedTime();
// kafka producer send message in background, the main purpose of track is to count how many message sent in action
ActionLogContext.track("kafka", elapsedTime);
logger.debug("publish, topic={}, key={}, message={}, elapsedTime={}", topic, key, new BytesParam(message), elapsedTime);
}
}
use of core.framework.impl.log.filter.BytesParam in project core-ng-project by neowu.
the class BeanBody method send.
@Override
public void send(Sender sender, ResponseHandlerContext context) {
validateBeanType(context.validator);
byte[] body = JSONMapper.toJSON(bean);
logger.debug("[response] body={}", new BytesParam(body));
sender.send(ByteBuffer.wrap(body));
}
Aggregations