pulsar known is the next generation messaging system, which two years of fame , a great kill kafka of momentum, if you want to quickly experience, the stand-alone version can build a local following steps: (mac environment + jdk8)
First, download
wget https://www.apache.org/dyn/mirrors/mirrors.cgi?action=download&filename=pulsar/pulsar-2.3.2/apache-pulsar-2.3.2-bin.tar.gz
The latest version is 2.3.2
Second, unzip
tar -zxvf apache-pulsar-2.3.2-bin.tar.gz
Third, the stand-alone mode is activated
cd apache-press-2.3.2 bin/pulsar standalone
Fourth, the test messaging
pulsar own client tools, send and receive test messages directly.
Message received command is as follows:
bin/pulsar-client consume my-topic -s "first-subscription"
Consumer represent a message from the "my-topic" of this topic, and specify the subscription name as "first-subscription"
Message command is as follows:
bin/pulsar-client produce my-topic --messages "hello pulsar"
It indicates a message transmitted to the my-topic this topic.
NOTE: When tested alone can start Terminal 2, in which a first running Consumer, and then produce the other one in the running
Attachment: If you want to write code to achieve java messaging, reference https://github.com/yjmyzz/pulsar-sample
Five, Function Test
function is a very promising features, it can be ejected in a message topic, and receive real-time post-processing, and then sent to another topic processing result, corresponding to lightweight flow calculations.
Api-examples.jar a package, which comes with some examples of the Function ./examples directory.
5.1 deployment Function
The deployment process, in fact, the jar package with processing logic, put on a cluster, the command is as follows:
bin/pulsar-admin functions create \ --jar examples/api-examples.jar \ --className org.apache.pulsar.functions.api.examples.ExclamationFunction \ --inputs persistent://public/default/exclamation-input \ --output persistent://public/default/exclamation-output \ --name exclamation
Generally it is to create a function, source of examples / api-examples.jar this file and specify a specific class name (as a jar package, you can write multiple function, you must specify the specific className), then this function into this parameter is Topic exclamation-input, processed results, and outputs to the exclamation-output, this last function in the name pulsar exclamation
Attached: ExclamationFunction following java source code, the logic is very simple, just after a plus input parameter!
package org.apache.pulsar.functions.api.examples; import java.util.function.Function; public class ExclamationFunction implements Function<String, String> { @Override public String apply(String input) { return String.format("%s!", input); } }
5.2 View a list of function deployed
bin/pulsar-admin functions list \ --tenant public \ --namespace default
5.3 Start consumer, view real-time processing results
bin/pulsar-client consume persistent://public/default/exclamation-output \ --subscription-name my-subscription \ --num-messages 0
5.4 start producers, the processing required to produce real-time material
bin/pulsar-client produce persistent://public/default/exclamation-input \ --num-produce 1 \ --messages "Hello world"
Reference article: