use of org.springframework.amqp.core.TopicExchange in project tutorials by eugenp.
the class BroadcastConfig method topicBindings.
@Bean
public List<Declarable> topicBindings() {
Queue topicQueue1 = new Queue(topicQueue1Name, false);
Queue topicQueue2 = new Queue(topicQueue2Name, false);
TopicExchange topicExchange = new TopicExchange(topicExchangeName);
return Arrays.asList(topicQueue1, topicQueue2, topicExchange, BindingBuilder.bind(topicQueue1).to(topicExchange).with("*.important.*"), BindingBuilder.bind(topicQueue2).to(topicExchange).with("user.#"));
}
use of org.springframework.amqp.core.TopicExchange in project fru-paqx-parent by dellemc-symphony.
the class vCenterServiceImpl method showSystem.
public CompletableFuture<vCenterSystemProperties> showSystem(final EndpointCredentials vcenterCredentials) {
final String requiredCapability = "vcenter-discover";
try {
final ListCapabilityProvidersResponse listCapabilityProvidersResponse = capabilityRegistryLookupManager.listCapabilityProviders(TimeUnit.SECONDS.toMillis(5));
for (final CapabilityProvider capabilityProvider : listCapabilityProvidersResponse.getResponse()) {
for (final Capability capability : capabilityProvider.getCapabilities()) {
LOG.debug("Found capability {}", capability.getProfile());
if (requiredCapability.equals(capability.getProfile())) {
LOG.debug("Found matching capability {}", capability.getProfile());
final List<EndpointProperty> endpointProperties = capability.getProviderEndpoint().getEndpointProperties();
final Map<String, String> amqpProperties = endpointProperties.stream().collect(Collectors.toMap(EndpointProperty::getName, EndpointProperty::getValue));
final String requestExchange = amqpProperties.get("request-exchange");
final String requestRoutingKey = amqpProperties.get("request-routing-key");
final TopicExchange responseExchange = new TopicExchange(amqpProperties.get("response-exchange"));
final String responseRoutingKey = amqpProperties.get("response-routing-key").replace("{replyTo}", "." + replyTo);
amqpAdmin.declareBinding(BindingBuilder.bind(responseQueue).to(responseExchange).with(responseRoutingKey));
LOG.debug("Adding binding {} {}", responseExchange.getName(), responseRoutingKey);
final UUID correlationId = UUID.randomUUID();
DiscoveryRequestInfoMessage requestMessage = new DiscoveryRequestInfoMessage();
requestMessage.setMessageProperties(new MessageProperties().withCorrelationId(correlationId.toString()).withReplyTo(replyTo).withTimestamp(new Date()));
try {
new URL(vcenterCredentials.getEndpointUrl());
} catch (MalformedURLException e) {
final CompletableFuture<vCenterSystemProperties> promise = new CompletableFuture<>();
promise.completeExceptionally(e);
return promise;
}
final DiscoveryRequestInfoMessage discoveryRequestInfo = new DiscoveryRequestInfoMessage();
Credentials credentials = new Credentials();
credentials.setUsername(vcenterCredentials.getUsername());
credentials.setAddress(vcenterCredentials.getEndpointUrl());
credentials.setPassword(vcenterCredentials.getPassword());
requestMessage.setCredentials(credentials);
final CompletableFuture<vCenterSystemProperties> promise = asyncAcknowledgement.register(correlationId.toString());
rabbitTemplate.convertAndSend(requestExchange, requestRoutingKey, requestMessage);
return promise;
}
}
}
} catch (CapabilityRegistryException e) {
LOG.error("Failed while looking up Capability Registry for {}", requiredCapability, e);
} catch (ServiceTimeoutException e) {
LOG.error("Service timed out while querying Capability Registry");
}
LOG.error("Unable to find required capability: {}", requiredCapability);
return CompletableFuture.completedFuture(null);
}
use of org.springframework.amqp.core.TopicExchange in project fru-paqx-parent by dellemc-symphony.
the class vCenterServiceImpl method requestVmDeletion.
@Override
public CompletableFuture<DestroyVmResponse> requestVmDeletion(final EndpointCredentials vcenterCredentials, final String uuid) {
final String requiredCapability = "vcenter-destroy-virtualMachine";
try {
final ListCapabilityProvidersResponse listCapabilityProvidersResponse = capabilityRegistryLookupManager.listCapabilityProviders(TimeUnit.SECONDS.toMillis(5));
for (final CapabilityProvider capabilityProvider : listCapabilityProvidersResponse.getResponse()) {
for (final Capability capability : capabilityProvider.getCapabilities()) {
LOG.debug("Found capability {}", capability.getProfile());
if (requiredCapability.equals(capability.getProfile())) {
LOG.debug("Found matching capability {}", capability.getProfile());
final List<EndpointProperty> endpointProperties = capability.getProviderEndpoint().getEndpointProperties();
final Map<String, String> amqpProperties = endpointProperties.stream().collect(Collectors.toMap(EndpointProperty::getName, EndpointProperty::getValue));
final String requestExchange = amqpProperties.get("request-exchange");
final String requestRoutingKey = amqpProperties.get("request-routing-key");
final TopicExchange responseExchange = new TopicExchange(amqpProperties.get("response-exchange"));
final String responseRoutingKey = amqpProperties.get("response-routing-key").replace("{replyTo}", "." + replyTo);
amqpAdmin.declareBinding(BindingBuilder.bind(responseQueue).to(responseExchange).with(responseRoutingKey));
LOG.debug("Adding binding {} {}", responseExchange.getName(), responseRoutingKey);
final UUID correlationId = UUID.randomUUID();
final DestroyVMRequestMessage requestMessage = new DestroyVMRequestMessage();
requestMessage.setUuid(uuid);
final MessageProperties messageProperties = new MessageProperties(new Date(), correlationId.toString(), replyTo);
requestMessage.setMessageProperties(messageProperties);
requestMessage.setCredentials(new Credentials(vcenterCredentials.getEndpointUrl(), vcenterCredentials.getPassword(), vcenterCredentials.getUsername()));
try {
new URL(vcenterCredentials.getEndpointUrl());
} catch (MalformedURLException e) {
final CompletableFuture<DestroyVmResponse> promise = new CompletableFuture<>();
promise.completeExceptionally(e);
return promise;
}
final CompletableFuture<DestroyVmResponse> promise = vmDeletionAsyncAcknowledgement.register(correlationId.toString());
rabbitTemplate.convertAndSend(requestExchange, requestRoutingKey, requestMessage);
return promise;
}
}
}
} catch (CapabilityRegistryException e) {
LOG.error("Failed while looking up Capability Registry for {}", requiredCapability, e);
} catch (ServiceTimeoutException e) {
LOG.error("Service timed out while querying Capability Registry");
}
return CompletableFuture.completedFuture(null);
}
use of org.springframework.amqp.core.TopicExchange in project fru-paqx-parent by dellemc-symphony.
the class vCenterServiceImpl method requestHostAddition.
@Override
public CompletableFuture<ClusterOperationResponse> requestHostAddition(final EndpointCredentials vcenterCredentials, final String hostname, final String clusterId, final String hostUsername, final String hostPassword) {
final String requiredCapability = "vcenter-addhostvcenter";
try {
final ListCapabilityProvidersResponse listCapabilityProvidersResponse = capabilityRegistryLookupManager.listCapabilityProviders(TimeUnit.SECONDS.toMillis(5));
for (final CapabilityProvider capabilityProvider : listCapabilityProvidersResponse.getResponse()) {
for (final Capability capability : capabilityProvider.getCapabilities()) {
LOG.debug("Found capability {}", capability.getProfile());
if (requiredCapability.equals(capability.getProfile())) {
LOG.debug("Found matching capability {}", capability.getProfile());
final List<EndpointProperty> endpointProperties = capability.getProviderEndpoint().getEndpointProperties();
final Map<String, String> amqpProperties = endpointProperties.stream().collect(Collectors.toMap(EndpointProperty::getName, EndpointProperty::getValue));
final String requestExchange = amqpProperties.get("request-exchange");
final String requestRoutingKey = amqpProperties.get("request-routing-key");
final TopicExchange responseExchange = new TopicExchange(amqpProperties.get("response-exchange"));
final String responseRoutingKey = amqpProperties.get("response-routing-key").replace("{replyTo}", "." + replyTo);
amqpAdmin.declareBinding(BindingBuilder.bind(responseQueue).to(responseExchange).with(responseRoutingKey));
LOG.debug("Adding binding {} {}", responseExchange.getName(), responseRoutingKey);
final UUID correlationId = UUID.randomUUID();
final ClusterOperationRequestMessage requestMessage = new ClusterOperationRequestMessage();
requestMessage.setCredentials(new Credentials(vcenterCredentials.getEndpointUrl(), vcenterCredentials.getPassword(), vcenterCredentials.getUsername()));
final ClusterOperationRequest clusterOperationRequest = new ClusterOperationRequest();
clusterOperationRequest.setHostName(hostname);
clusterOperationRequest.setClusterID(clusterId);
clusterOperationRequest.setUserName(hostUsername);
clusterOperationRequest.setPassword(hostPassword);
clusterOperationRequest.setClusterOperation(ClusterOperationRequest.ClusterOperation.ADD_HOST);
requestMessage.setClusterOperationRequest(clusterOperationRequest);
try {
new URL(vcenterCredentials.getEndpointUrl());
} catch (MalformedURLException e) {
final CompletableFuture<ClusterOperationResponse> promise = new CompletableFuture<>();
promise.completeExceptionally(e);
return promise;
}
final CompletableFuture<ClusterOperationResponse> promise = vcenterClusterOperationAsyncAcknowledgement.register(correlationId.toString());
LOG.info("Host addition request with correlation id [{}]", correlationId.toString());
rabbitTemplate.convertAndSend(requestExchange, requestRoutingKey, requestMessage);
return promise;
}
}
}
} catch (CapabilityRegistryException e) {
LOG.error("Failed while looking up Capability Registry for {}", requiredCapability, e);
} catch (ServiceTimeoutException e) {
LOG.error("Service timed out while querying Capability Registry");
}
LOG.error("Unable to find required capability: {}", requiredCapability);
return CompletableFuture.completedFuture(null);
}
use of org.springframework.amqp.core.TopicExchange in project fru-paqx-parent by dellemc-symphony.
the class vCenterServiceImpl method requestConsulRegistration.
public CompletableFuture<ConsulRegistryResult> requestConsulRegistration(final EndpointCredentials vcenterCredentials) {
final String requiredCapability = "vcenter-consul-register";
try {
final ListCapabilityProvidersResponse listCapabilityProvidersResponse = capabilityRegistryLookupManager.listCapabilityProviders(TimeUnit.SECONDS.toMillis(5));
for (final CapabilityProvider capabilityProvider : listCapabilityProvidersResponse.getResponse()) {
for (final Capability capability : capabilityProvider.getCapabilities()) {
LOG.debug("Found capability {}", capability.getProfile());
if (requiredCapability.equals(capability.getProfile())) {
LOG.debug("Found matching capability {}", capability.getProfile());
final List<EndpointProperty> endpointProperties = capability.getProviderEndpoint().getEndpointProperties();
final Map<String, String> amqpProperties = endpointProperties.stream().collect(Collectors.toMap(EndpointProperty::getName, EndpointProperty::getValue));
final String requestExchange = amqpProperties.get("request-exchange");
final String requestRoutingKey = amqpProperties.get("request-routing-key");
final TopicExchange responseExchange = new TopicExchange(amqpProperties.get("response-exchange"));
final String responseRoutingKey = amqpProperties.get("response-routing-key").replace("{replyTo}", "." + replyTo);
amqpAdmin.declareBinding(BindingBuilder.bind(responseQueue).to(responseExchange).with(responseRoutingKey));
LOG.debug("Adding binding {} {}", responseExchange.getName(), responseRoutingKey);
final UUID correlationId = UUID.randomUUID();
ConsulRegisterRequestMessage requestMessage = new ConsulRegisterRequestMessage();
requestMessage.setMessageProperties(new MessageProperties().withCorrelationId(correlationId.toString()).withReplyTo(replyTo).withTimestamp(new Date()));
try {
new URL(vcenterCredentials.getEndpointUrl());
} catch (MalformedURLException e) {
final CompletableFuture<ConsulRegistryResult> promise = new CompletableFuture<>();
promise.completeExceptionally(e);
return promise;
}
final RegistrationInfo registrationInfo = new RegistrationInfo(vcenterCredentials.getEndpointUrl(), vcenterCredentials.getPassword(), vcenterCredentials.getUsername());
requestMessage.setRegistrationInfo(registrationInfo);
final CompletableFuture<ConsulRegistryResult> promise = consulRegisterAsyncAcknowledgement.register(correlationId.toString());
rabbitTemplate.convertAndSend(requestExchange, requestRoutingKey, requestMessage);
return promise;
}
}
}
} catch (CapabilityRegistryException e) {
LOG.error("Failed while looking up Capability Registry for {}", requiredCapability, e);
} catch (ServiceTimeoutException e) {
LOG.error("Service timed out while querying Capability Registry");
}
LOG.error("Unable to find required capability: {}", requiredCapability);
return CompletableFuture.completedFuture(null);
}
Aggregations