Skip to content

tspannhw/Meetup-YourFirstEventDrivenApp

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

Meetup-YourFirstEventDrivenApp

NJ Meetup - Build an event-driven architecture with Apache Pulsar

Code Along


bin/pulsar-admin tenants create meetup
bin/pulsar-admin namespaces create meetup/newjersey
bin/pulsar-admin tenants list 
bin/pulsar-admin namespaces list meetup
bin/pulsar-admin topics create persistent://meetup/newjersey/first
bin/pulsar-admin topics list meetup/newjersey

bin/pulsar-client consume "persistent://meetup/newjersey/first" -s first-reader -n 0

Pulsar SQL Code Along

bin/pulsar sql

show catalogs;
show schemas in pulsar;
show tables in pulsar."meetup/newjersey";
describe pulsar."meetup/newjersey"."first";

select * from pulsar."meetup/newjersey"."first";

select __key__, from_utf8(__value__), 
           __publish_time__, __message_id__,
           __producer_name__
from pulsar."meetup/newjersey"."first"
order by __publish_time__ desc;

exit;

Monitoring Code Along

curl http://localhost:8080/admin/v2/persistent/meetup/newjersey/first/stats | python3 -m json.tool

bin/pulsar-admin topics stats-internal persistent://meetup/newjersey/first

curl http://pulsar1:8080/metrics/

bin/pulsar-admin topics stats-internal persistent://meetup/newjersey/first

bin/pulsar-admin topics peek-messages --count 5 --subscription mqtt-reader persistent://meetup/newjersey/first

bin/pulsar-admin topics subscriptions persistent://meetup/newjersey/first

Cleanup This Exercise (You don't have to)

bin/pulsar-admin topics delete persistent://meetup/newjersey/first
bin/pulsar-admin namespaces delete meetup/newjersey
bin/pulsar-admin tenants delete meetup

Web Pages For Viewing

Python Testing

import pulsar
client = pulsar.Client('pulsar://localhost:6650')
consumer = client.subscribe('persistent://meetup/newjersey/first',subscription_name='my-sub')
while True:
    msg = consumer.receive()
    print("Received message: '%s'" % msg.data())
    consumer.acknowledge(msg)
client.close()

import pulsar
client = pulsar.Client('pulsar://localhost:6650')
producer = client.create_producer('persistent://meetup/newjersey/first')
producer.send(('Hi Meetup people' ).encode('utf-8'))
client.close()

import pulsar
client = pulsar.Client('pulsar://localhost:6650')
producer = client.create_producer('persistent://meetup/newjersey/first')
producer.send(('Hi Meetup people' ).encode('utf-8'))
client.close()

bin/pulsar-client consume "persistent://meetup/newjersey/first" -s first-reader -n 0


GoLang App

go get -u "github.com/apache/pulsar-client-go/pulsar"

go build -o app produce.go

package main

import (
        "log"
        "time"
        "fmt"
        "context"
        "github.com/apache/pulsar-client-go/pulsar"
)

func main() {

        client, err := pulsar.NewClient(pulsar.ClientOptions{
        URL:               "pulsar://localhost:6650",
        OperationTimeout:  30 * time.Second,
        ConnectionTimeout: 30 * time.Second,
        })

        if err != nil {
                log.Fatal(err)
        }

        producer, err := client.CreateProducer(pulsar.ProducerOptions{
                Topic: "persistent://meetup/newjersey/first",
        })

        _, err = producer.Send(context.Background(), &pulsar.ProducerMessage{
    Payload: []byte("hello"),
})

defer producer.Close()

if err != nil {
    fmt.Println("Failed to publish message", err)
}
fmt.Println("Published message")


}

References

For Ubuntu 18.04 on AMD65

  • go1.13.9.linux-amd64.tar.gz

About

NJ Meetup - Build an event-driven architecture with Apache Pulsar

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published