use of ProducerDummy.Messages.Hmac_Message in project amos2022ss02-audit-chain by amosproj.
the class ConsumerClientBlockchain method start.
/**
* Start receiving Messages from the RabbitMQ Server.
* @throws IOException if an I/O error occurs
* @throws TimeoutException if the timeout expires
*/
public void start() throws IOException, TimeoutException {
System.out.println("Starting to receive Messages.");
Connection connection = this.factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages.");
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
AggregateMessage message;
try {
message = (AggregateMessage) AggregateConsumerClient.deserializeMessage(delivery.getBody());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
Vector<Message> messages = message.getMessages();
Integer[] seq_numbers = new Integer[messages.size()];
String[] transactions = new String[messages.size()];
int iterator = 0;
for (Message m : messages) {
// if you use instanceOf you could accept both Messages and HmacMessages
m = (Hmac_Message) m;
seq_numbers[iterator] = m.getSequence_number();
transactions[iterator] = m.getMessage();
iterator++;
}
blockchain.addABlock(seq_numbers, transactions);
// blockchain.printBlockchain();
};
channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> {
});
}
Aggregations