Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option for queue name to be emitted along with message content #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/jvm/backtype/storm/spout/KestrelThriftSpout.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class KestrelThriftSpout extends BaseRichSpout {
private String _queueName = null;
private SpoutOutputCollector _collector;
private Scheme _scheme;
private boolean _shouldEmitQueueName = false;

private List<KestrelClientInfo> _kestrels;
private int _emitIndex;
Expand Down Expand Up @@ -93,30 +94,51 @@ public void closeClient() {
}
}

public KestrelThriftSpout(List<String> hosts, int port, String queueName, Scheme scheme) {
public KestrelThriftSpout(List<String> hosts, int port, String queueName, Scheme scheme, boolean shouldEmitQueueName) {
if(hosts.isEmpty()) {
throw new IllegalArgumentException("Must configure at least one host");
}
_port = port;
_hosts = hosts;
_queueName = queueName;
_scheme = scheme;
_shouldEmitQueueName = shouldEmitQueueName;
}

public KestrelThriftSpout(List<String> hosts, int port, String queueName, Scheme scheme) {
this(hosts, port, queueName, scheme, false);
}

public KestrelThriftSpout(String hostname, int port, String queueName, Scheme scheme, boolean shouldEmitQueueName) {
this(Arrays.asList(hostname), port, queueName, scheme, shouldEmitQueueName);
}

public KestrelThriftSpout(String hostname, int port, String queueName, Scheme scheme) {
this(Arrays.asList(hostname), port, queueName, scheme);
}

public KestrelThriftSpout(String hostname, int port, String queueName, boolean shouldEmitQueueName) {
this(hostname, port, queueName, new RawScheme(), shouldEmitQueueName);
}

public KestrelThriftSpout(String hostname, int port, String queueName) {
this(hostname, port, queueName, new RawScheme());
}

public KestrelThriftSpout(List<String> hosts, int port, String queueName, boolean shouldEmitQueueName) {
this(hosts, port, queueName, new RawScheme(), shouldEmitQueueName);
}

public KestrelThriftSpout(List<String> hosts, int port, String queueName) {
this(hosts, port, queueName, new RawScheme());
}

public Fields getOutputFields() {
return _scheme.getOutputFields();
if (_shouldEmitQueueName) {
List<String> fields = _scheme.getOutputFields().toList();
fields.add("queue");
return new Fields(fields);
} else return _scheme.getOutputFields();
}

int _messageTimeoutMillis;
Expand Down Expand Up @@ -174,6 +196,7 @@ public boolean bufferKestrelGet(int index) {

for(Item item : items) {
List<Object> retItems = _scheme.deserialize(item.get_data());
if (_shouldEmitQueueName) retItems.add(_queueName);

if (retItems != null) {
EmitItem emitItem = new EmitItem(retItems, new KestrelSourceId(index, item.get_id()));
Expand Down