Routers direct messages to an appropriate message channel typically based on what is in the payload or header of a message. Routers do not alter the message like a transformer. Routers don’t remove messages from the system like a filter can. They simply provide forks in the road of message channels in a Spring Integration (SI) application. In this lab, you explore a few commonly used SI routers. Specifically, in this lab you will: Configure and use an XPath router to route XML payload messages. Define a recipient router to send the same message to a collection of channels. Scenario – Route using XPath expression In previous filter Lab, we used XPath expressions in filters to remove or discard some XML messages from the system. In a similar fashion, as will be demonstrated in this part of the lab, an XPath router uses an XPath expression to determine which message channel receives a message containing XML in its payload. In particular, note that the application already contains an inbo...
Hadoop MapReduce’s word count becomes very simple with the Spark shell. In this recipe, we are going to create a simple 1-line text file, upload it to the Hadoop distributed file system (HDFS), and use Spark to count occurrences of words. Let’s see how: 1. Create the words directory by using the following command: $ mkdir words 2. Get into the words directory: $ cd words 3. Create a sh.txt text file and enter “to be or not to be” in it: $ echo “to be or not to be” > sh.txt 4. Start the Spark shell: $ spark-shell 5. Load the words directory as RDD: Scala> val words = sc.textFile(“hdfs://localhost:9000/user/hduser/ words”) 6. Count the number of lines ( result: 1): Scala> words.count 7. Divide the line (or lines) into multiple words: Scala> val wordsFlatMap = words.flatMap(_.split(“\\W+”)) 8. Convert word to (word,1)—that is, output 1 as the value for each occurrence of word as a key: Scala> val wordsMap = wordsFla...