protected void unregister(String name, String consumerGroup) { this.clientFactory.getOrCreateEventProcessorHost(name, consumerGroup).unregisterEventProcessor() .whenComplete((s, t) -> { if (t != null) { log.warn(String.format("Failed to unregister consumer '%s' with group '%s'", name, consumerGroup), t); } }); }
@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 User send(@RequestBody User user) { this.eventHubOperation.sendAsync(EVENT_HUB_NAME, MessageBuilder.withPayload(user).build()); return user; }
private CompletableFuture<Void> doSend(String eventHubName, PartitionSupplier partitionSupplier, List<EventData> eventData) { try { EventHubClient client = this.clientFactory.getOrCreateClient(eventHubName); if (partitionSupplier == null) { return client.send(eventData); } else if (!Strings.isNullOrEmpty(partitionSupplier.getPartitionId())) { return this.clientFactory.getOrCreatePartitionSender(eventHubName, partitionSupplier.getPartitionId()) .send(eventData); } else if (!Strings.isNullOrEmpty(partitionSupplier.getPartitionKey())) { return client.send(eventData, partitionSupplier.getPartitionKey()); } else { return client.send(eventData); } } catch (EventHubRuntimeException e) { log.error(String.format("Failed to send to '%s' ", eventHubName), e); CompletableFuture<Void> future = new CompletableFuture<>(); future.completeExceptionally(e); return future; } }
@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; } }
private CompletableFuture<Void> doSend(String eventHubName, PartitionSupplier partitionSupplier, List<EventData> eventData) { try { EventHubClient client = this.clientFactory.getOrCreateClient(eventHubName); if (partitionSupplier == null) { return client.send(eventData); } else if (!Strings.isNullOrEmpty(partitionSupplier.getPartitionId())) { return this.clientFactory.getOrCreatePartitionSender(eventHubName, partitionSupplier.getPartitionId()) .send(eventData); } else if (!Strings.isNullOrEmpty(partitionSupplier.getPartitionKey())) { return client.send(eventData, partitionSupplier.getPartitionKey()); } else { return client.send(eventData); } } catch (EventHubRuntimeException e) { log.error(String.format("Failed to send to '%s' ", eventHubName), e); CompletableFuture<Void> future = new CompletableFuture<>(); future.completeExceptionally(e); return future; } }
protected void unregister(String name, String consumerGroup) { this.clientFactory.getOrCreateEventProcessorHost(name, consumerGroup).unregisterEventProcessor() .whenComplete((s, t) -> { if (t != null) { log.warn(String.format("Failed to unregister consumer '%s' with group '%s'", name, consumerGroup), t); } }); }
@PostMapping("/messages") public String send(@RequestParam("message") String message) { this.eventHubOperation.sendAsync(EVENT_HUB_NAME, MessageBuilder.withPayload(message).build()); return message; }
protected void register(String name, String consumerGroup, EventHubProcessor eventProcessor) { EventProcessorHost host = this.clientFactory.getOrCreateEventProcessorHost(name, consumerGroup); host.registerEventProcessorFactory(context -> eventProcessor, buildEventProcessorOptions(startPosition)); }
protected void register(String name, String consumerGroup, EventHubProcessor eventProcessor) { EventProcessorHost host = this.clientFactory.getOrCreateEventProcessorHost(name, consumerGroup); host.registerEventProcessorFactory(context -> eventProcessor, buildEventProcessorOptions(startPosition)); }