Skip to content

Instantly share code, notes, and snippets.

@johndemic
johndemic / gist:3916027
Created October 19, 2012 03:13
Stock Quote Flow
<flow name="main">
<zeromq:inbound-endpoint address="tcp://*:9090" socket-operation="bind"
exchange-pattern="request-response"/>
<protobuf:deserialize
protobufClass="com.acmesoft.stock.model.serialization.protobuf.StockQuoteRequestBuffer"/>
<expression-transformer
expression="com.acmesoft.stock.model.StockQuoteRequest.fromProtocolBuffer(payload)"/>
<component class="com.acmesoft.stock.service.StockDataServiceImpl"/>
<expression-transformer
expression="return com.acmesoft.stock.model.StockQuote.toProtocolBuffer(payload)"/>
@johndemic
johndemic / gist:3916021
Created October 19, 2012 03:11
pom.xml with zeromq dependency
<dependency>
<groupId>org.zeromq</groupId>
<artifactId>zmq</artifactId>
<version>2.2.0</version>
<systemPath>/usr/local/lib/zmq.jar</systemPath>
<scope>system</scope>
</dependency>
@johndemic
johndemic / StockQuoteResponse.java
Created October 19, 2012 03:07
StockQuoteResponse Protocol Buffer Helper Methods
public static StockQuoteResponseBuffer toProtocolBuffer(List<StockQuote> quotes) {
StockQuoteResponseBuffer.Builder responseBuilder = StockQuoteResponseBuffer.newBuilder();
for (StockQuote quote : quotes) {
responseBuilder.addResult(StockQuoteBuffer.newBuilder()
.setAdjustedClose(quote.getAdjustedClose())
.setClose(quote.getClose())
.setDate(quote.getDate().getTime())
.setHigh(quote.getHigh())
.setLow(quote.getLow())
@johndemic
johndemic / StockQuoteRequest.java
Created October 19, 2012 03:05
StockQuoteRequest Helper Methods
public byte[] toProtocolBufferAsBytes() {
return StockQuoteRequestBuffer.newBuilder()
.setSymbol(symbol)
.setStart(startDate.getTime())
.setEnd(endDate.getTime()).build().toByteArray();
}
public static StockQuoteRequest fromProtocolBuffer(StockQuoteRequestBuffer buffer) {
StockQuoteRequest request = new StockQuoteRequest();
@johndemic
johndemic / pom.xml
Created October 19, 2012 03:03
maven-protoc-plugin
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<groupId>com.google.protobuf.tools</groupId>
<artifactId>maven-protoc-plugin</artifactId>
<configuration>
<protocExecutable>/usr/local/bin/protoc</protocExecutable>
</configuration>
<executions>
<execution>
<goals>
@johndemic
johndemic / StockQuoteResponseMessage.proto
Created October 19, 2012 03:00
StockQuoteResponseMessage
package com.acmesoft.zeromq;
option java_package = "com.acmesoft.stock.model.serialization.protobuf";
option optimize_for = SPEED;
option java_multiple_files = true;
message StockQuoteResponseBuffer {
repeated StockQuoteBuffer result = 1;
}
@johndemic
johndemic / StockQuoteRequestMessage.proto
Created October 19, 2012 02:59
StockQuoteRequestMessage
package com.acmesoft.zeromq;
option java_package = "com.acmesoft.stock.model.serialization.protobuf";
option optimize_for = SPEED;
option java_multiple_files = true;
message StockQuoteRequestBuffer {
required string symbol = 1;
required int64 start = 2;
@johndemic
johndemic / StockDataService.java
Created October 19, 2012 02:50
StockDataService.java
public interface StockDataService {
public List<StockQuote> getQuote(StockQuoteRequest request);
}
@johndemic
johndemic / StockQuiteRequest.java
Created October 19, 2012 02:48
StockQuiteRequest.java
public class StockQuoteRequest implements Serializable {
String symbol;
Date startDate;
Date endDate;
@johndemic
johndemic / StockQuote.java
Created October 19, 2012 02:47
StockQuote.java
public class StockQuote implements Serializable {
String symbol;
Date date;
Double open;
Double high;