Created
March 17, 2014 20:09
-
-
Save workmaster2n/9607227 to your computer and use it in GitHub Desktop.
Timestamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.voltdb.client.ClientFactory; | |
import com.google.gson.Gson; | |
import com.rabbitmq.client.Channel; | |
import com.rabbitmq.client.Connection; | |
import com.rabbitmq.client.ConnectionFactory; | |
import com.rabbitmq.client.QueueingConsumer; | |
public class Recv { | |
private final static String QUEUE_NAME = "tracked_points"; | |
public static void main(String[] argv) throws Exception { | |
ConnectionFactory factory = new ConnectionFactory(); | |
factory.setUri("amqp://safdsf:usdfc@tiger.cloudamqp.com/vkawda"); | |
Connection connection = factory.newConnection(); | |
Channel channel = connection.createChannel(); | |
// channel.queueDeclare(QUEUE_NAME, false, false, false, null); | |
channel.exchangeDeclare(QUEUE_NAME, "fanout"); | |
String queueName = channel.queueDeclare().getQueue(); | |
channel.queueBind(queueName, QUEUE_NAME, ""); | |
System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); | |
QueueingConsumer consumer = new QueueingConsumer(channel); | |
channel.basicConsume(queueName, true, consumer); | |
org.voltdb.client.Client client; | |
client = ClientFactory.createClient(); | |
client.createConnection("localhost"); | |
while (true) { | |
QueueingConsumer.Delivery delivery = consumer.nextDelivery(); | |
String message = new String(delivery.getBody()); | |
System.out.println(" [x] Received '" + message + "'"); | |
Gson gson = new Gson(); | |
TrackedPoint tracked_point = gson.fromJson(message, TrackedPoint.class); | |
tracked_point.calculate_epoch(); | |
client.callProcedure("AddTrackedPoint", tracked_point.getX(), tracked_point.getY(), tracked_point.getFrequency(), tracked_point.getSolution_time(), tracked_point.getRecorded_at()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Received '{"frequency":1064000,"x":35.3922424,"y":52.1479721,"solution_time":"2014-03-17T20:05:49.2300963Z"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE tracked_points ( | |
x DECIMAL, | |
y DECIMAL, | |
frequency INTEGER, | |
solution_time VARCHAR(45), | |
recorded_at TIMESTAMP, | |
created_at TIMESTAMP DEFAULT NOW | |
); | |
CREATE PROCEDURE FROM CLASS AddTrackedPoint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
public class TrackedPoint { | |
private String solution_time; | |
private double x; | |
private double y; | |
private int frequency; | |
private long recorded_at; | |
public String getSolution_time() { | |
return solution_time; | |
} | |
public void setSolution_time(String solution_time) { | |
this.solution_time = solution_time; | |
} | |
public double getX() { | |
return x; | |
} | |
public void setX(double x) { | |
this.x = x; | |
} | |
public double getY() { | |
return y; | |
} | |
public void setY(double y) { | |
this.y = y; | |
} | |
public int getFrequency() { | |
return frequency; | |
} | |
public void setFrequency(int frequency) { | |
this.frequency = frequency; | |
} | |
public long getRecorded_at() { | |
return recorded_at; | |
} | |
public void setRecorded_at(long recorded_at) { | |
this.recorded_at = recorded_at; | |
} | |
public void calculate_epoch() throws ParseException { | |
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'kk:mm:ss.SX"); | |
Date date = df.parse(this.solution_time); | |
setRecorded_at(date.getTime()*1000); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment