ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Humphrey <hmmlo...@gmail.com>
Subject Re: Kindly tell me where to find these jar files.
Date Mon, 29 May 2017 12:04:45 GMT
I think it's not hard to do and once you start implement the interface you
will figure out by yourself.

- May I ask *what tool do you use* to parse the Schema that converts the
object to this json?

Here is what I did:

I created an object, called TulpeBus which would be the kind of messages
(objects) i'll be receiving from Kafka. When I receive this object from
kafka I'll extract the BusId and use that key for ignite and the value is
the rest of the content as one string, by calling my *specialized*
toString() method on the object.

In my example I'm passing an object. You probably will be getting an byte[]
from kafka which will need to be converted back to an object by the tool you
used to convert it in first place to byte[] before sending it to kafka.

*Here is myExtractor implementing the interface:*
public class MyExtractor implements StreamSingleTupleExtractor<TupleBUS,
Integer, String> {
	@Override
	public Entry<Integer, String> extract(TupleBUS msg) {
		return new AbstractMap.SimpleEntry<Integer, String>(msg.getBusId(),
msg.toString());
	}
}

*Here is my TupleBus with specialized toString() method:*
public class TupleBUS {
	int busId;
	int busNumber;
	long busDate;
	String route;
	long lastUpdated;

	public TupleBUS(int busId, int busNumber, long busDate, String route, long
lastUpdated) {
		super();
		this.busId = busId;
		this.busNumber = busNumber;
		this.busDate = busDate;
		this.route = route;
		this.lastUpdated = lastUpdated;
	}
	public int getBusId() {
		return busId;
	}
	public int getBusNumber() {
		return busNumber;
	}
	public long getBusDate() {
		return busDate;
	}
	public String getRoute() {
		return route;
	}
	public long getLastUpdated() {
		return lastUpdated;
	}

	@Override
	public String toString() {
		return " [busNumber=" + busNumber + ", busDate=" + busDate + ", route=" +
route + ", lastUpdated=" + lastUpdated + "]";
	}
}

*Here is a main method to testIt:*
public class TestMyExtractor {
	public static void main(String[] args) {
		TupleBUS tulpe = new TupleBUS(3, 100, 1484092800000L, "A-B",
1495650596335L);
		MyExtractor extractor = new MyExtractor();
		System.out.println(extractor.extract(tulpe));
	}
}

*Output:*
3= [busNumber=100, busDate=1484092800000, route=A-B,
lastUpdated=1495650596335]

I hope this example helps.




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Kindly-tell-me-where-to-find-these-jar-files-tp12649p13192.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Mime
View raw message