mirror of https://github.com/apache/cloudstack.git
fix the bug in creating exchange on AMQP
This commit is contained in:
parent
7d9381edd3
commit
abd7685928
|
|
@ -29,6 +29,7 @@ public class Event {
|
|||
String description;
|
||||
String publisher;
|
||||
String date;
|
||||
String resourceType;
|
||||
|
||||
public Event(String category, String type, String routingKey) {
|
||||
this.category = category;
|
||||
|
|
@ -58,7 +59,7 @@ public class Event {
|
|||
|
||||
public void setDescription (Object message) {
|
||||
Gson gson = new Gson();
|
||||
this.description = gson.toJson(description).toString();
|
||||
this.description = gson.toJson(message).toString();
|
||||
}
|
||||
|
||||
public String getEventPublisher() {
|
||||
|
|
|
|||
|
|
@ -102,20 +102,21 @@ public class RabbitMQEventBus implements EventBus {
|
|||
}
|
||||
}
|
||||
|
||||
private void createExchange(String eventCategory) throws Exception {
|
||||
String exchangeName = getExchangeName(eventCategory);
|
||||
private void createExchange(String exchangeName) throws Exception {
|
||||
try {
|
||||
_channel.exchangeDeclare(exchangeName, "topic", true);
|
||||
} catch (java.io.IOException exception) {
|
||||
s_logger.error("Failed to create exchange on RabbitMQ server for the event category " + eventCategory);
|
||||
s_logger.error("Failed to create exchange" + exchangeName + " on RabbitMQ server");
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
private void publishEventToExchange(String exchangeName, String routingKey, String eventDescription) throws Exception {
|
||||
try {
|
||||
_channel.txSelect();
|
||||
byte[] messageBodyBytes = eventDescription.getBytes();
|
||||
_channel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, messageBodyBytes);
|
||||
_channel.txCommit();
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Failed to publish event " + routingKey + " on exchange " + exchangeName +
|
||||
" of message broker due to " + e.getMessage());
|
||||
|
|
|
|||
Loading…
Reference in New Issue