26
sierpnia
2010
At work, we're mainly integrating services and systems, and since we're on a constant lookout for new, better technologies, ways to do things easier, make them more sustainable, we're trying to
Usually we use Apache Camel for this task, which is a Swiss-knife for integration engineer. What's more, this tools corresponds well with our approach to integration solutions:
However, at first sight Apache Camel seems to have some drawbacks mainly in the area of practical solutions ;-). It's very handy tool if you need to use it as a pipeline with some marginal processing of the data that passes through it. It gets a lot harder to wrap your head around if you consider some branching and intermediate calls to external services. This may be tricky to write properly in Camel's DSL.
Here is a simple pipeline example:
And here the exact scenario we're discussing:
What I'd like to show is the solution to this problem. Well, if you're using a recent version of Camel this may be easier, a little different, but should still more-or-less work this way. This code is written for Apache Camel 1.4 - a rather antic version, but that's what we're forced to use. Oh, well.
Ok, enough whining!
So, I create a test class to illustrate the case. The route defined in TestRouter class is responsible for:
Here is some code for this:
public class SimpleTest {
public void setUp() throws Exception {
TestRouter tr = new TestRouter();
ctx.addRoutes(tr);
}
@Test
public void shouldCheck() throws Exception {
ctx.createProducerTemplate().send("direct:in", getInOut("<a/>"));
}
class TestRouter extends RouteBuilder {
public void configure() throws Exception {
((ProcessorType<ProcessorType>)from("direct:in")
.setProperty("operation").xpath("local-name(/*)", String.class)
.multicast(new MergeAggregationStrategy())
.to("direct:a", "direct:b", "direct:c")
.end()
.setBody().simple("${in.body} "))
.bean(RequestEnricher.class, "enrich")
.to("log:pl.touk.debug");
from("direct:a").process(new SimpleContentSetter("<aaaa/>"));
from("direct:b").process(new SimpleContentSetter("<bbbb param1=\"1\" param2=\"2\" param3=\"3\"/>"));
from("direct:c").process(new SimpleContentSetter("<cccc/>"));
}
}
}
What's unusual in this code is the fact, that what normally Camel does when you write a piece of DSL like:
.to("direct:a", "direct:b", "direct:c")
is pass input to service a, than a's output gets passed to b, becomes it's input, than b's output becomes c's input. The problem being, you loose the output from a and b, not mentioning that you might want to send the same input to all three services.
That's where a little tool called multicast() comes in handy. It offers you the ability to aggregate the outputs of those services. You may even create an AggregationStrategy that will do it the way you like. Below class, MergeAggregationStrategy does exactly that kind of work - it joins outputs from all three services. A lot of info about proper use of AggregationStrategy-ies can be found in this post by Torsten Mielke.
public class MergeAggregationStrategy implements AggregationStrategy {
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
if (oldExchange.isFailed()) {
return oldExchange;
}
transformMessage(oldExchange.getIn(), newExchange.getIn());
transformMessage(oldExchange.getOut(), newExchange.getOut());
return newExchange;
}
private void transformMessage(Message oldM, Message newM) {
String oldBody = oldM.getBody(String.class);
String newBody = newM.getBody(String.class);
newM.setBody(oldBody + newBody);
}
}
However nice this may look (or not), what you're left with is a mix of multiple XMLs. Normally this won't do you much good. Better thing to do is to parse this output in some way. What we're using for this is a Groovy :). Which is great for the task of parsing XML. A lot less verbose than ordinary Java.
Let's assume a scenario, that the aggregated output, currently looking like this:
is to be processed with the following steps in mind:
public class RequestEnricher {
public String enrich(@Property(name = "operation") String operation, Exchange ex) {
use(DOMCategory) {
def dhl = new groovy.xml.Namespace("http://example.com/common/dhl/schema", 'dhl')
def pc = new groovy.xml.Namespace("http://example.com/pc/types", 'pc')
def doc = new XmlParser().parseText(ex.in.body)
def pcRequest = doc."aaaa"[0]
["param1", "param2", "param3"].each() {
def node = doc.'**'[("" + it)][0]
if (node)
pcRequest['@' + it] = node.text()
}
gNodeListToString([pcRequest])
}
}
String gNodeListToString(list) {
StringBuilder sb = new StringBuilder();
list.each { listItem ->
StringWriter sw = new StringWriter();
new XmlNodePrinter(new PrintWriter(sw)).print(listItem)
sb.append(sw.toString());
}
return sb.toString();
}
}
What we're doing here, especially the last line of enrich method is the conversion to String. There are some problems for Camel if we spit out Groovy objects. The rest is just some Groovy specific ways of manipulating XML. But looking into enrich method's parameters, there is @Property annotation used, which binds the property assigned earlier in a router code to one of the arguments. That is really cool feature and there are more such annotations:
This pretty much concludes the subject :) Have fun, and if in doubt, leave a comment with your question!
18
sierpnia
2010
Some time ago, I've attended MeetBSD conference in Kraków. This BSD event is held yearly in either Warsaw, or Kraków. Due to relatively small group of people that registered there was only one track, which had both good and bad sides - you didn't have to choose from myriads of lectures, but there was no way to skip boring ones either. Well, I guess this kind of niche conference - about operating system :) - will not attract bigger attention.
It took place on 2nd-3rd of July, 2010, so this review is rather dated :) However, I'd like to keep this as reminder. I've arrived to the conference site, which was located in building of the Faculty of Mathematics and Computer Science a few minutes after the official start of the conference. I had been traveling from Warsaw the same day, and the only train that would not require me to get up at some night hour would arrive a bit too late. Oh well :)
I grabbed a tea and some biscuits and entered the series of lectures.
The first thing to listen to was a Welcome intro - quite nice one. Conducted by a guy from Cisco (AFAIK). He was talking about the opportunities for Kraków and how it will become a Polish Silicon Valley in near future, etc. Actually I don't share his believes but the talk was ok.
Then came Dru Lavigne with some insight into BSD Certification program. Actually, does anybody use this? Come one. Do we really need another certification process? I for sure don't see the need, especially for the BSD community. However the trend is good, may help popularize BSDs among enterprise leaders, because if something is certified, than it can be used in big enterprises, right? :)
Sławek Żak talked about NoSQL. Although the talk gave a bit of info about what the idea is and how does it compare to normal DBs, I did not find his presentation entertaining. In my opinion, there was not enough emphasis on the difference in usage for such databases. The talk about NoSQL I'd attended on Javarsovia was a lot better.
Next talk, presented by Attilio Rao was very, very technical. It was about "VFS/Vnode interface in FreeBSD". It was rather an API presentation, and introduction on how to implement an FS in FreeBSD infrastructure, than a conference talk. This kind of presentation would be good suited for FreeBSD kernel developers not sysadmins.
Jakub Klama's talk on the process of porting FreeBSD to Da Vinci embedded system was interesting. It had some photos of the board, tackled a few technical corners, but caught my attention. Well done!
Out guy among FreeBSD hackers - Paweł Jakub Dawidek - gave speech about HAST - High Availability STorage. In other words he implemented DRBD for FreeBSD. Sadly, for me this is just catching up with what Linux has in mainline since 2.6.33 (it was working very well even before that). It's not so feature rich as DRBD, but the project is slowly maturing. Nevertheless, it's good to finally have this on board.
Then an inconspicuous guy come onto the stage. Came from Bulgaria, named Nikolay Aleksandrov, that guy gave a talk titled Developing high speed FreeBSD. And the subject was astounding. He works for a major Bulgarian ISP and due to lack of cash to buy some serious networking gear, he wrote a FreeBSD extension that would sit in-between network adapter and the kernel and do all the hard work like routing, VLANs, and more. His goal was to make it lighting fast, and as far as his results showed, he succeeded. This talk was really amazing, he did what would normally take hundreds of thousands of dollars - in cash and skills - in his free time, or at least as a pet project.
Well, I'd skipped the first lecture of the day, because of laziness ;)
Had decide to pack myself and arrive to listen about what can freebsd borrow from AIX. Jan Srzednicki talked about some nice tools from the AIX world. He proposed that adding an educational, console-based tool for conducting basic (and even not so basic) tasks, would encourage people to learn the system. I think it would work. However the rest of his ideas weren't good enough - at least not for me.
Next thing in line was The new USB stack. Interesting talk about new USB stack development, conducted by Hans Petter Selasky. This guy was really passionate about USB things ;-)
Martin Matuska presented his set of shell scripts that allow to create mfsBSD - an in-memory FreeBSD install. Since I'm already doing this kind of things with OpenBSD, the talk was entertaining.
Marcko Zec and Network stack virtualization. This was about extending FreeBSD to be able to create lots of compartmentalized environments with their own network stacks. As noted in the presentation: the solution still has problems with graceful shutdown of the stack. Still not stable enough - but very promising.
The closing presentation, given by Warner Losh (very knowledgeable guy behing bsdimp.blogspot.com) on the subject Using FreeBSD in a commercial settings. The talk was not what I've expected, but nevertheless was very interesting. It was about branching and merging back changes in case of using FreeBSD as a base for some commercial products. This could be easily applied to any other Open Source project. Warner described possible strategies for branching and performing merges, he noted also pros and cons of all the described solutions.
All in all, that was a fun time. Even thou I don't use any BSD as my primary system at this time, and my BSD skills are a bit rusty, the talks were nice enough :) for a hobbist like me.
12
sierpnia
2010
Last Monday, while coming home from Sweden, I had ~7h layover between my flights. Since Arlanda Airport does not offer a lot to do, at least not for me and not for 7h, I had decided to go to Stockholm. This post sums up a few nice places, that I'd like to visit on my next trip there.
I took Arlanda Express, fast train that takes you directly from the airport to Stockholm. On board, you travel with 200km/h in good enough conditions. The trains takes you near the Central station in 20 minutes, which is great! The main venue I planned to see was Gamla Stan. All the attractions were also there, on the island.
The first noteworthy place on the road was Christina's costume salon. Unfortunately closed on the day of my visit, however since it was recommended to me, and the place look interesting I plan on paying it another visit. This shop offers a lot of costumes, different sizes, themes. Website is: Shop's page
|
|
Seems like just a usual gift shop, but has this unique feeling, this Norsk spirit. Shop offers many fantastic gifts and souvenirs, but unfortunately they don't come cheap. Nevertheless, worth visiting and perhaps buying. Especially nice were little metal statues of Viking gods. Handfaste - The Viking Shop
|
|
Neat little workshop, that does metal signs on request, from your design. Very good quality. Actually there are quite a few of such workshops nearby, but this may serve as a reminder. Det "lille" Skyltmakerie
|
|
Awesome sci-fi, fantasy bookshop. Lots of stuff, comics, books, dvds, collectibles, etc. I strolled into it when going back to the airport, that's why I had only around 5 minutes to look around. But the shop is definitely worth visiting. They offer English books among Swedish-lang ones, with 50:50 proportions in quantity. Science Fiction Bokhandeln
|
|
The darkest and best supplied metal shop I've ever seen - thou haven't seen many of such stores. Again, stumbled on it on my way to the airport, so had only around 5 minutes to look around, scan through t-shirts, etc :D Sound Pollution
|
|
Some t-shirt shop, had also lots of underwear, dark costumes, etc. I think there may be more to it than I noticed.
|
|
Unfortunately hadn't found this during my wandering. Will try next time: Roberta Settels shoes designs
|
|
Don't know the name of this packed with designer items place, but it was warm and cosy :) Prices were high and the utensils neat. Bore marks of "Swedish design school".
|
|
Maps created with Google Maps Static API:
Nice thing to use! Now I'm searching for a way to may the maps dynamic on click :)21 kwietnia 2010, 18:01:59 | Reaktywacja o-filmoramy? |
Mam nadzieję, że wreszcie jednak ruszę z blogiem filmowym, po raz kolejny należy mu się reaktywacja.
http://o-filmorama.blogspot.com