本文整理汇总了Java中org.springframework.kafka.support.SendResult类的典型用法代码示例。如果您正苦于以下问题:Java SendResult类的具体用法?Java SendResult怎么用?Java SendResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SendResult类属于org.springframework.kafka.support包,在下文中一共展示了SendResult类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
public void send(String topic, LifecycleEvent message) {
// the KafkaTemplate provides asynchronous send methods returning a Future
ListenableFuture<SendResult<String, Object>> future = kafkaTemplate.send(topic, message);
// register a callback with the listener to receive the result of the send asynchronously
future.addCallback(new ListenableFutureCallback<SendResult<String, Object>>() {
@Override
public void onSuccess(SendResult<String, Object> result) {
LOGGER.info("sent message='{}' with offset={}", message,
result.getRecordMetadata().offset());
}
@Override
public void onFailure(Throwable ex) {
LOGGER.error("unable to send message='{}'", message, ex);
}
});
}
示例2: createCell
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.GET, path = "/createCell")
public void createCell(@NotNull @RequestParam String name, @NotNull @RequestParam CellType cellType) throws ExecutionException, InterruptedException {
JSONObject cell = new JSONObject();
cell.put("name", name);
cell.put("type", cellType);
ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topic, cell.toString());
future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
@Override
public void onSuccess(SendResult<String, String> result) {
System.out.println("success");
}
@Override
public void onFailure(Throwable ex) {
System.out.println("failed");
}
});
}
示例3: send
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
public void send(String topic, String data) {
ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topic, data);
future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
@Override
public void onSuccess(SendResult<String, String> result) {
logger.info("Success on sending message \"" + data + "\" to topic " + topic);
}
@Override
public void onFailure(Throwable ex) {
logger.error("Error on sending message \"" + data + "\", stacktrace " + ex.getMessage());
}
});
}
示例4: sendMessage
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
public void sendMessage(String topic, String message) {
// the KafkaTemplate provides asynchronous send methods returning a
// Future
ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topic, message);
// you can register a callback with the listener to receive the result
// of the send asynchronously
future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
@Override
public void onSuccess(SendResult<String, String> result) {
logger.info("sent message='{}' with offset={}", message, result.getRecordMetadata().offset());
}
@Override
public void onFailure(Throwable ex) {
logger.error("unable to send message='{}'", message, ex);
}
});
// alternatively, to block the sending thread, to await the result,
// invoke the future’s get() method
}
示例5: sendMessage
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
public void sendMessage(Student student) {
ListenableFuture<SendResult<String, Student>> future = kafkaTemplate
.send(env.getProperty("kafka.topics"), student);
future.addCallback(new ListenableFutureCallback<SendResult<String, Student>>() {
@Override
public void onFailure(Throwable ex) {
LOGGER.error("Inside Exception");
}
@Override
public void onSuccess(SendResult<String, Student> result) {
LOGGER.info("Inside Success");
}
});
}
示例6: send
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
/**
* Metodo funndamental para la informacion en Kafka.
* @param topic Topico de Kafka.
* @param data Datos a enviar.
*/
public void send(String topic, String data) {
ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topic, data); //Valido por si solo para el manejo de la informacion.
future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
@Override
public void onSuccess(SendResult<String, String> result) {
logger.info("Success on sending message \"" + data + "\" to topic " + topic);
}
@Override
public void onFailure(Throwable ex) {
logger.error("Error on sending message \"" + data + "\", stacktrace " + ex.getMessage());
}
});
}
示例7: send
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
public void send(String topic, String data) {
ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topic, data);
future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
@Override
public void onSuccess(SendResult<String, String> result) {
logger.info(result);
logger.info("Success on sending message \"" + data + "\" to topic " + topic);
}
@Override
public void onFailure(Throwable ex) {
logger.error("Error on sending message \"" + data + "\", stacktrace " + ex.getMessage());
}
});
}
示例8: onSuccess
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
/**
* Called when the {@link ListenableFuture} completes with success.
* <p>Note that Exceptions raised by this method are ignored.
*
* @param result the result
*/
@Override
public void onSuccess(SendResult<String, String> result) {
log.info("sent message='{}' with offset={}", result.getProducerRecord(),
result.getRecordMetadata().offset());
onCompleted(result);
}
示例9: send
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
public ListenableFuture<SendResult<String, Event>> send(Event event, String topic) {
LOGGER.info("Event payload='{}'", event);
return kafkaTemplate.send(topic, event);
}
示例10: send
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
/**
* send message to kafka.<BR/>
*
* @param topic topic
* @param key key
* @param message value
*/
public void send(String topic, K key, V message, ListenableFutureCallback<SendResult<K, V>> callback) {
ListenableFuture<SendResult<K, V>> future = kafkaTemplate.send(topic, key, message);
if (callback != null)
future.addCallback(callback);
}
示例11: onCompleted
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
/**
* Called after super.onSuccess().<BR/>
*
* @param result the result
*/
abstract public void onCompleted(SendResult<String, String> result);
示例12: onCompleted
import org.springframework.kafka.support.SendResult; //导入依赖的package包/类
/**
* Called after super.onSuccess().<BR/>
*
* @param result the result
*/
@Override
public void onCompleted(SendResult<String, String> result) {
}