Reputation: 2363
I am having problems getting a basic java application to compile with Maven. This is my first time using the program, which was chosen for dependency management.
The application is as follows
package com.ender.storm;
import com.ender.storm.RedisPubSubSpout;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
RedisPubSubSpout spout = RedisPubSubSpout("redis://129.196.196.166", 6379, "WebhookEvents");
System.out.println( "Hello World!" );
}
}
The RedisPubSubSpout class was copied from https://github.com/stormprocessor/storm-redis-pubsub/blob/master/src/jvm/yieldbot/storm/spout/RedisPubSubSpout.java
and placed in the same folder as the App class.
EDIT: The class in my folder is as follows
package com.ender.storm;
import static backtype.storm.utils.Utils.tuple;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.log4j.Logger;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisPubSub;
import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.base.BaseRichSpout;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.tuple.Fields;
import backtype.storm.utils.Utils;
public class RedisPubSubSpout extends BaseRichSpout {
static final long serialVersionUID = 737015318988609460L;
static Logger LOG = Logger.getLogger(RedisPubSubSpout.class);
SpoutOutputCollector _collector;
final String host;
final int port;
final String pattern;
LinkedBlockingQueue<String> queue;
JedisPool pool;
public RedisPubSubSpout(String host, int port, String pattern) {
this.host = host;
this.port = port;
this.pattern = pattern;
}
class ListenerThread extends Thread {
LinkedBlockingQueue<String> queue;
JedisPool pool;
String pattern;
public ListenerThread(LinkedBlockingQueue<String> queue, JedisPool pool, String pattern) {
this.queue = queue;
this.pool = pool;
this.pattern = pattern;
}
public void run() {
JedisPubSub listener = new JedisPubSub() {
@Override
public void onMessage(String channel, String message) {
queue.offer(message);
}
@Override
public void onPMessage(String pattern, String channel, String message) {
queue.offer(message);
}
@Override
public void onPSubscribe(String channel, int subscribedChannels) {
// TODO Auto-generated method stub
}
@Override
public void onPUnsubscribe(String channel, int subscribedChannels) {
// TODO Auto-generated method stub
}
@Override
public void onSubscribe(String channel, int subscribedChannels) {
// TODO Auto-generated method stub
}
@Override
public void onUnsubscribe(String channel, int subscribedChannels) {
// TODO Auto-generated method stub
}
};
Jedis jedis = pool.getResource();
try {
jedis.psubscribe(listener, pattern);
} finally {
pool.returnResource(jedis);
}
}
};
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
_collector = collector;
queue = new LinkedBlockingQueue<String>(1000);
pool = new JedisPool(new JedisPoolConfig(),host,port);
ListenerThread listener = new ListenerThread(queue,pool,pattern);
listener.start();
}
public void close() {
pool.destroy();
}
public void nextTuple() {
String ret = queue.poll();
if(ret==null) {
Utils.sleep(50);
} else {
_collector.emit(tuple(ret));
}
}
public void ack(Object msgId) {
// TODO Auto-generated method stub
}
public void fail(Object msgId) {
// TODO Auto-generated method stub
}
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("message"));
}
public boolean isDistributed() {
return false;
}
}
error log shows
[INFO] Compiling 2 source files to <file_path>/projects/mvn/Storm/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] <file_path>/projects/mvn/Storm/src/main/java/com/ender/storm/App.java:[13,34] cannot find symbol
symbol: method RedisPubSubSpout(java.lang.String,int,java.lang.String)
location: class com.ender.storm.App
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
My maven version is
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.7.0_75, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-i386/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-44-generic", arch: "i386", family: "unix"
With a pom.xml file of
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ender.storm</groupId>
<artifactId>Storm</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Storm</name>
<url>http://maven.apache.org</url>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArgument></compilerArgument>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>0.9.1-incubating</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.6.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
And I am compiling on Ubuntu 14.04.
If I comment out the spout
//RedisPubSubSpout spout = RedisPubSubSpout...
it compiles fine. Can someone please explain what I am doing wrong? I have never encountered and issue like this before.
Upvotes: 0
Views: 2412
Reputation: 2485
This line
RedisPubSubSpout spout = RedisPubSubSpout("redis://129.196.196.166", 6379, "WebhookEvents");
Should be
RedisPubSubSpout spout = new RedisPubSubSpout("redis://129.196.196.166", 6379, "WebhookEvents");
You're missing the new
operator
Your current syntax is trying to find a local function named RedisPubSubSpout
Upvotes: 3