当前位置: 首页>>代码示例>>Java>>正文


Java KafkaListener类代码示例

本文整理汇总了Java中org.springframework.kafka.annotation.KafkaListener的典型用法代码示例。如果您正苦于以下问题:Java KafkaListener类的具体用法?Java KafkaListener怎么用?Java KafkaListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


KafkaListener类属于org.springframework.kafka.annotation包,在下文中一共展示了KafkaListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: receive

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
/**
 * Receives messages from WorkFlowManager queue.
 *
 * @param record the message object instance
 */
@KafkaListener(id = "northbound-listener-health-check", topics = Topic.HEALTH_CHECK)
public void receive(final String record) {
    try {
        logger.trace("message received");
        Message message = MAPPER.readValue(record, Message.class);
        if (Destination.NORTHBOUND.equals(message.getDestination())) {
            logger.debug("message received: {}", record);
            InfoMessage info = (InfoMessage) message;
            HealthCheckInfoData healthCheck = (HealthCheckInfoData) info.getData();
            messages.put(healthCheck.getId(), healthCheck);
        } else {
            logger.trace("Skip message: {}", message);
        }
    } catch (IOException exception) {
        logger.error("Could not deserialize message: {}", record, exception);
    }
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:23,代码来源:KafkaHealthCheckMessageConsumer.java

示例2: onMessage

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
/**
 * Read the topic and push the data to the DB The @KafkaListener annotation
 * provides a mechanism for simple POJO listeners
 */
@Override
@KafkaListener(id = "consumer", topics = "#{'${kafka.topics}'.split('\\\\ ')}")
public void onMessage(ConsumerRecord<String, Student> data, Acknowledgment acknowledgment) {

	try {
		LOGGER.info("Record value is : " + data.value());
		LOGGER.info("Offset value is : " + data.offset());
		LOGGER.info("Topic is : " + data.topic());
		LOGGER.info("Partition is : " + data.partition());
		LOGGER.info("printing the calendar object:" + data.value());
		service.create(data.value());
		LOGGER.info("pushed the data to DB successfuly");

	} catch (Exception e) {
		LOGGER.error("Push the messaged to Error Stream : " + e);
	} finally {
		acknowledgment.acknowledge();
	}

}
 
开发者ID:sarojrout,项目名称:spring-tutorial,代码行数:25,代码来源:KafkaEventConsumer.java

示例3: on

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
/**
 * Updates the current stock by reducing the inventory items by the amount of the individual line items in the order.
 * 
 * @param message will never be {@literal null}.
 */
@Transactional
@KafkaListener(topics = "orders")
void on(OrderCompleted message) {

	log.info("Order completed: {}", message.getOrderId().toString());

	message.getLineItems().stream() //
			.peek(it -> log.info("Decreasing quantity of product {} by {}.", it.getProductNumber(), it.getQuantity()))
			.forEach(it -> inventory.updateInventoryItem(it.getProductNumber(), it.getQuantity()));
}
 
开发者ID:olivergierke,项目名称:sos,代码行数:16,代码来源:KafkaIntegration.java

示例4: kafkaListener

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
@KafkaListener(topics = {"inventory"})
public void kafkaListener(ConsumerRecord<?, byte[]> record) {
    Optional<?> messages = Optional.ofNullable(record.value());
    if (messages.isPresent()) {
        byte[] msg = (byte[]) messages.get();
        LogUtil.debug(LOGGER, "接收到Myth分布式框架消息对象:{}", () -> msg);
        mythMqReceiveService.processMessage(msg);

    }
}
 
开发者ID:yu199195,项目名称:myth,代码行数:11,代码来源:KafkaConsumer.java

示例5: receive

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
/**
 * Receives messages from WorkFlowManager queue.
 *
 * @param record the message object instance
 */
@KafkaListener(id = "northbound-listener", topics = Topic.NORTHBOUND)
public void receive(final String record) {
    try {
        logger.trace("message received");
        Message message = MAPPER.readValue(record, Message.class);
        if (Destination.NORTHBOUND.equals(message.getDestination())) {
            logger.debug("message received: {}", record);
            messages.put(message.getCorrelationId(), message);
        } else {
            logger.trace("Skip message: {}", message);
        }
    } catch (IOException exception) {
        logger.error("Could not deserialize message: {}", record, exception);
    }
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:21,代码来源:KafkaMessageConsumer.java

示例6: onProductAdded

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
/**
 * Creates a new {@link InventoryItem} for the product that was added.
 * 
 * @param message will never be {@literal null}.
 */
@KafkaListener(topics = "products")
public void onProductAdded(ProductAdded message) throws IOException {

	Optional<InventoryItem> item = inventory.findByProductId(message.getProductId());

	if (item.isPresent()) {
		log.info("Inventory item for product {} already available!", message.getProductId());
		return;
	}

	log.info("Creating inventory item for product {}.", message.getProductId());

	item.orElseGet(() -> inventory.save(InventoryItem.of(message.getProductId(), message.getName(), 0L)));
}
 
开发者ID:olivergierke,项目名称:sos,代码行数:20,代码来源:KafkaIntegration.java

示例7: kafkaListener

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
@KafkaListener(topics = {"account"})
public void kafkaListener(ConsumerRecord<?, byte[]> record) {
    Optional<?> messages = Optional.ofNullable(record.value());
    if (messages.isPresent()) {
        byte[] msg = (byte[]) messages.get();
        LogUtil.debug(LOGGER, "接收到Myth分布式框架消息对象:{}", () -> msg);
        mythMqReceiveService.processMessage(msg);

    }
}
 
开发者ID:yu199195,项目名称:myth,代码行数:11,代码来源:KafkaConsumer.java

示例8: listenOperations

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
@KafkaListener(id = "op-listener", topics = "operation-events", containerFactory = "operationsKafkaListenerContainerFactory")
private void listenOperations(ConsumerRecord<String, Operation> data) throws EventStoreException {
    log.info("Incoming Message: " + data.key()+ " "+ data.value());
    for (AggregateListener snapshotRecorder : aggregateListeners) {
        snapshotRecorder.listenOperations(data);
    }
}
 
开发者ID:kloiasoft,项目名称:eventapis,代码行数:8,代码来源:SpringKafkaOpListener.java

示例9: execute

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
@Override
@KafkaListener(topics = "PaymentSuccessEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(PaymentSuccessEvent dto) throws EventStoreException, EventPulisherException, ConcurrentEventException {
    Order order = orderQuery.queryEntity(dto.getOrderId());

    if (order.getState() == OrderState.PAYMENT_READY) {
        log.info("Payment is processing : " + dto);
        return eventRepository.recordAndPublish(order.getEventKey(),new OrderPaidEvent(dto.getPaymentId()));
    } else
        throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
 
开发者ID:kloiasoft,项目名称:eventapis,代码行数:12,代码来源:PaymentSuccessEventHandler.java

示例10: execute

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
@Override
@KafkaListener(topics = "StockReservedEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(StockReservedEvent dto) throws EventStoreException, EventPulisherException, ConcurrentEventException {
    Order order = orderQuery.queryEntity(dto.getOrderId());

    if (order.getState() == OrderState.PROCESSING) {
        PaymentProcessEvent paymentProcessEvent = new PaymentProcessEvent(order.getId(),new PaymentInformation(order.getPaymentAddress(),order.getAmount(),order.getCardInformation()));
        log.info("Payment is processing : " + dto);
        return eventRepository.recordAndPublish(order,paymentProcessEvent);
    } else
        throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
 
开发者ID:kloiasoft,项目名称:eventapis,代码行数:13,代码来源:StockReservedEventHandler.java

示例11: listen

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
@KafkaListener(id = "foo", topics = "topic1", group = "group1")
public void listen(ConsumerRecord<?, ?> record) {
	log.debug("Checkout launched externally with message: " + record.toString());
	// The order id would be deserialized from the received message
	String orderId = "Fake order id";
	Map<String, Object> variables = new HashMap<>();
	variables.put("orderId", orderId);
	runtimeService.startProcessInstanceByKey("hello", variables);
}
 
开发者ID:underscorenico,项目名称:skeleton-oms-java,代码行数:10,代码来源:Listener.java

示例12: listen

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
@KafkaListener(topics = "hello.t")
public void listen(String data) {
	// Retrieve the process instance id (execution id key in the message)
	String processInstanceId = data;
	log.debug("Resume process instance: " + processInstanceId);
	// Signal (resume) execution
	runtimeService.signal(processInstanceId);
}
 
开发者ID:underscorenico,项目名称:skeleton-oms-java,代码行数:9,代码来源:Listener.java

示例13: testListener

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
@KafkaListener(topics = {"bootcwenaoTopic"})
public void testListener(ConsumerRecord<?, ?> record) {

    Optional<?> messages = Optional.ofNullable(record.value());

    if (messages.isPresent()) {
        Object msg = messages.get();
        System.out.println("  this is the testTopic send message: " + msg);
    }

}
 
开发者ID:cwenao,项目名称:springboot_cwenao,代码行数:12,代码来源:KafkaListeners.java

示例14: listen

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
@KafkaListener(topics = {"test-topic"})
public void listen(ConsumerRecord<?, ?> record) {
    logger.debug("listen1 ");
    Optional<?> kafkaMessage = Optional.ofNullable(record.value());
    if (kafkaMessage.isPresent()) {
        Object message = kafkaMessage.get();
        logger.debug("listen1 : {}", message);
    }
}
 
开发者ID:ctodb,项目名称:push,代码行数:10,代码来源:KafkaConsumer.java

示例15: onMessage

import org.springframework.kafka.annotation.KafkaListener; //导入依赖的package包/类
/**
     * Message consumer handle.<BR/>
     *
     * @param record     message object
     */
    @KafkaListener(topics = "tracking")
    public void onMessage(ConsumerRecord<String, String> record) {
        log.debug("received message: {}", record);
        try {
            TrackingEntity tracking = JsonMapper.readJsonObject(record.value(), TrackingEntity.class);
//            trackingService.insert(tracking);
            // JPA
            //trackingRepository.save(tracking);
            databaseManager.createTracking(tracking);

        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
 
开发者ID:iotoasis,项目名称:SO,代码行数:20,代码来源:TrackingConsumerHandler.java


注:本文中的org.springframework.kafka.annotation.KafkaListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。