@PostConstruct public void subscribeToEventHub() { this.eventHubOperation .setCheckpointConfig(CheckpointConfig.builder().checkpointMode(CheckpointMode.MANUAL).build()); this.eventHubOperation.subscribe(EVENT_HUB_NAME, CONSUMER_GROUP, this::messageReceiver, String.class); }
@PostMapping("/messages") public String send(@RequestParam("message") String message) { this.eventHubOperation.sendAsync(EVENT_HUB_NAME, MessageBuilder.withPayload(message).build()); return message; }
@Override protected MessageProducer createConsumerEndpoint(ConsumerDestination destination, String group, ExtendedConsumerProperties<EventHubConsumerProperties> properties) { this.eventHubOperation.setStartPosition(properties.getExtension().getStartPosition()); CheckpointConfig checkpointConfig = CheckpointConfig.builder().checkpointMode(properties.getExtension().getCheckpointMode()) .checkpointCount(properties.getExtension().getCheckpointCount()).build(); this.eventHubOperation.setCheckpointConfig(checkpointConfig); boolean anonymous = !StringUtils.hasText(group); if (anonymous) { group = "anonymous." + UUID.randomUUID().toString(); this.eventHubOperation.setStartPosition(StartPosition.LATEST); } EventHubInboundChannelAdapter inboundAdapter = new EventHubInboundChannelAdapter(destination.getName(), this.eventHubOperation, group); inboundAdapter.setBeanFactory(getBeanFactory()); return inboundAdapter; }
@Bean public EventHubInboundChannelAdapter messageChannelAdapter( @Qualifier(INPUT_CHANNEL) MessageChannel inputChannel, EventHubOperation eventhubOperation) { eventhubOperation.setCheckpointConfig(CheckpointConfig.builder().checkpointMode(CheckpointMode.MANUAL).build()); EventHubInboundChannelAdapter adapter = new EventHubInboundChannelAdapter(EVENTHUB_NAME, eventhubOperation, CONSUMER_GROUP); adapter.setOutputChannel(inputChannel); return adapter; } }
@PostMapping("/messages") public User send(@RequestBody User user) { this.eventHubOperation.sendAsync(EVENT_HUB_NAME, MessageBuilder.withPayload(user).build()); return user; }