use of com.azure.core.credential.AzureKeyCredential in project vividus by vividus-framework.
the class EventGridServiceTests method shouldSendCustomEvent.
@Test
void shouldSendCustomEvent() {
@SuppressWarnings("unchecked") EventGridPublisherClient<BinaryData> client = mock(EventGridPublisherClient.class);
try (MockedConstruction<EventGridPublisherClientBuilder> builderConstructor = mockConstruction(EventGridPublisherClientBuilder.class, (mock, context) -> {
when(mock.endpoint(ENDPOINT)).thenReturn(mock);
ArgumentMatcher<AzureKeyCredential> matcher = c -> KEY.equals(c.getKey());
when(mock.credential(argThat(matcher))).thenReturn(mock);
when(mock.buildCustomEventPublisherClient()).thenReturn(client);
});
MockedStatic<BinaryData> mockedEvent = mockStatic(BinaryData.class)) {
BinaryData event = mock(BinaryData.class);
mockedEvent.when(() -> BinaryData.fromString(PAYLOAD)).thenReturn(event);
topic.setEventSchema(EventSchema.CUSTOM);
SERVICE.sendEvent(topic, PAYLOAD);
verify(client).sendEvents(List.of(event));
}
}
use of com.azure.core.credential.AzureKeyCredential in project vividus by vividus-framework.
the class EventGridService method sendEvent.
public void sendEvent(Topic topic, String payload) {
EventGridPublisherClientBuilder builder = new EventGridPublisherClientBuilder().endpoint(topic.getEndpoint()).credential(new AzureKeyCredential(topic.getKey()));
EventSchema eventSchema = topic.getEventSchema();
eventSchema.sendEvent(builder, payload);
}
use of com.azure.core.credential.AzureKeyCredential in project DataSpaceConnector by eclipse-dataspaceconnector.
the class AzureEventExtension method registerListeners.
private void registerListeners(ServiceExtensionContext context) {
var config = new AzureEventGridConfig(context);
var topicName = config.getTopic();
var endpoint = config.getEndpoint(topicName);
monitor.info("AzureEventExtension: will use topic endpoint " + endpoint);
var publisherClient = new EventGridPublisherClientBuilder().credential(new AzureKeyCredential(Objects.requireNonNull(vault.resolveSecret(topicName), "Did not find secret in vault: " + endpoint))).endpoint(endpoint).buildEventGridEventPublisherAsyncClient();
AzureEventGridPublisher publisher = new AzureEventGridPublisher(context.getConnectorId(), monitor, publisherClient);
var processObservable = context.getService(TransferProcessObservable.class, true);
if (processObservable != null) {
processObservable.registerListener(publisher);
}
}
Aggregations