This page will describe how to create an extractor using java. A lot of this code can be copied and pasted. The only major part is the processFile function. You can find this example also in our code repository at: https://opensource.ncsa.illinois.edu/stash/projects/MMDB/repos/extractors-examples/browse/java
The first step in the example is to setup some global variables that will be used in the rest of the code.
configuration
// name where rabbitmq is running private static String rabbitmqhost = "localhost"; // name to show in rabbitmq queue list private static String exchange = "medici"; // name to show in rabbitmq queue list private static String extractorName = "wordCount"; // username and password to connect to rabbitmq private static String username = null; private static String password = null; // accept any type of file that is text private static String messageType = "*.file.text.#"; // secret key used to connect to medici, this will eventually be // part of the message received. private static String secretKey = "r1ek3rs";
A convenience function to return status messages to Medici
statusUpdate
private void statusUpdate(Channel channel, AMQP.BasicProperties header, String fileid, String status) throws IOException { logger.debug("[" + fileid + "] : " + status); Map<String, Object> statusreport = new HashMap<String, Object>(); statusreport.put("file_id", fileid); statusreport.put("extractor_id", extractorName); statusreport.put("status", status); statusreport.put("start", dateformat.format(new Date())); AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().correlationId(header.getCorrelationId()).build(); channel.basicPublish(exchange, header.getReplyTo(), props, mapper.writeValueAsBytes(statusreport)); }
The main method will listen for messages on the message bus.
statusUpdate