Apache Nutch is an extensible and scalable web crawler
Fixes for NUTCH-2132: Added new properties
r0ann3lbc9a2c859c2b
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex ea7df89a6..6c20e4fe7 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -2272,6 +2272,7 @@ visit https://wiki.apache.org/nutch/SimilarityScoringFilter-->Currently there exists an implemtation for RabbitMQ producer.</description></property>+<property><name>publisher.order</name><value></value>@@ -2279,7 +2280,9 @@ visit https://wiki.apache.org/nutch/SimilarityScoringFilter-->The order in which the publisher queues would be loaded</description></property>+<!-- RabbitMQ properties -->+<property><name>rabbitmq.exchange.server</name><value></value>@@ -2287,6 +2290,7 @@ visit https://wiki.apache.org/nutch/SimilarityScoringFilter-->Name for the exchange server to use. Default - "fetcher_log"</description></property>+<property><name>rabbitmq.exchange.type</name><value></value>@@ -2294,6 +2298,7 @@ visit https://wiki.apache.org/nutch/SimilarityScoringFilter-->There are a few exchange types available: direct, topic, headers and fanout. Default "fanout".</description></property>+<property><name>rabbitmq.host</name><value></value>@@ -2301,13 +2306,62 @@ visit https://wiki.apache.org/nutch/SimilarityScoringFilter-->Host on which the RabbitMQ server is running. Default "localhost".</description></property>+<property>- <name>rabbitmq.queue.routingkey</name>+ <name>rabbitmq.port</name>+ <value></value>+ <description>+ Port on which the RabbitMQ server is listening. Default "15672".+ </description>+</property>++<property>+ <name>rabbitmq.virtualhost</name><value></value><description>- The routingKey used by publisher to publish messages to specific queues. If the exchange type is "fanout", then this property is ignored.+ Default 'null'</description></property>+<property>+ <name>rabbitmq.username</name>+ <value></value>+ <description>+ Default 'null'+ </description>+</property>++<property>+ <name>rabbitmq.password</name>+ <value></value>+ <description>+ Default 'null'+ </description>+</property>++<property>+ <name>rabbitmq.queue.name</name>+ <value></value>+ <description>+ Default 'fanout.queue'+ </description>+</property>++<property>+ <name>rabbitmq.queue.durable</name>+ <value></value>+ <description>+ Default 'true'+ </description>+</property>++<property>+ <name>rabbitmq.queue.routingkey</name>+ <value></value>+ <description>+ Default is 'fanout.key'+ The routingKey used by publisher to publish messages to specific queues. If the exchange type is "fanout", then this property is ignored.+ </description>+</property></configuration>diff --git a/src/plugin/publish-rabbitmq/src/java/org/apache/nutch/publisher/rabbitmq/RabbitMQPublisherImpl.java b/src/plugin/publish-rabbitmq/src/java/org/apache/nutch/publisher/rabbitmq/RabbitMQPublisherImpl.javaindex 3fafbaf42..4d44fb580 100644--- a/src/plugin/publish-rabbitmq/src/java/org/apache/nutch/publisher/rabbitmq/RabbitMQPublisherImpl.java+++ b/src/plugin/publish-rabbitmq/src/java/org/apache/nutch/publisher/rabbitmq/RabbitMQPublisherImpl.java@@ -33,22 +33,56 @@ public class RabbitMQPublisherImpl implements NutchPublisher{private static String EXCHANGE_SERVER;private static String EXCHANGE_TYPE;+private static String HOST;+ private static int PORT;+ private static String VIRTUAL_HOST;+ private static String USERNAME;+ private static String PASSWORD;++ private static String QUEUE_NAME;+ private static boolean QUEUE_DURABLE;+ private static String QUEUE_ROUTING_KEY;+private static final Logger LOG = LoggerFactory.getLogger(RabbitMQPublisherImpl.class);+private static Channel channel;@Overridepublic boolean setConfig(Configuration conf) {- try{- EXCHANGE_SERVER = conf.get("rabbitmq.exchange.server", "fetcher_log");- EXCHANGE_TYPE = conf.get("rabbitmq.exchange.type", "fanout");- HOST = conf.get("rabbitmq.host", "localhost");- ConnectionFactory factory = new ConnectionFactory();- factory.setHost(HOST);+ try {+ EXCHANGE_SERVER = conf.get("rabbitmq.exchange.server", "fetcher_log");//+ EXCHANGE_TYPE = conf.get("rabbitmq.exchange.type", "fanout");//++ HOST = conf.get("rabbitmq.host", "localhost");//+ PORT = conf.getInt("rabbitmq.port", 15672);//+ VIRTUAL_HOST = conf.get("rabbitmq.virtualhost", null);//+ USERNAME = conf.get("rabbitmq.username", null);+ PASSWORD = conf.get("rabbitmq.password", null);++ QUEUE_NAME = conf.get("rabbitmq.queue.name", "fanout.queue");//+ QUEUE_DURABLE = conf.getBoolean("rabbitmq.queue.durable", true);//+ QUEUE_ROUTING_KEY = conf.get("rabbitmq.queue.routingkey", "fanout.key");//++ ConnectionFactory factory = new ConnectionFactory();+ factory.setHost(HOST);+ factory.setPort(PORT);++ if(VIRTUAL_HOST != null) {+ factory.setVirtualHost(VIRTUAL_HOST);+ }++ if(USERNAME != null) {+ factory.setUsername(USERNAME);+ factory.setPassword(PASSWORD);+ }Connection connection = factory.newConnection();channel = connection.createChannel();channel.exchangeDeclare(EXCHANGE_SERVER, EXCHANGE_TYPE);+ channel.queueDeclare(QUEUE_NAME, QUEUE_DURABLE, false, false, null);+ channel.queueBind(QUEUE_NAME, EXCHANGE_SERVER, QUEUE_ROUTING_KEY);+LOG.info("Configured RabbitMQ publisher");return true;}catch(Exception e) {@@ -60,9 +94,8 @@ public class RabbitMQPublisherImpl implements NutchPublisher{@Overridepublic void publish(Object event, Configuration conf) {- String rountingKey = conf.get("rabbitmq.queue.routingkey", "");try {- channel.basicPublish(EXCHANGE_SERVER, rountingKey, null, getJSONString(event).getBytes());+ channel.basicPublish(EXCHANGE_SERVER, QUEUE_ROUTING_KEY, null, getJSONString(event).getBytes());} catch (Exception e) {LOG.error("Error occured while publishing - {}", StringUtils.stringifyException(e));}