pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/sofyan48/pubsub-router

us" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-71a44d5be3f782c5.css" /> GitHub - sofyan48/pubsub-router: Route your action in gcp Pubsub easy
Skip to content

sofyan48/pubsub-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GCP PubSub Router

Pubsub Router Local Development

Route your action in gcp Pubsub easy

Installing

go get github.com/sofyan48/pubsub-router

Setup Client

package main

import (
	"context"
	"fmt"
	"os"

	"cloud.google.com/go/pubsub"
	"github.com/joho/godotenv"
	pubsubrouter "github.com/sofyan48/pubsub-router"
)

func main() {
	err := godotenv.Load()
	if err != nil {
		fmt.Println("error: ", err)
	}
	cfg := &pubsubrouter.Config{
		Type:                    "service_account",
		ProjectID:               os.Getenv("GOOGLE_PROJECT_ID"),
		PrivateKeyID:            os.Getenv("GOOGLE_PRIVATE_KEY_ID"),
		PrivateKey:              os.Getenv("GOOGLE_PRIVATE_KEY"),
		ClientEmail:             os.Getenv("GOOGLE_CLIENT_EMAIL"),
		ClientID:                os.Getenv("GOOGLE_CLIENT_ID"),
		AuthURI:                 os.Getenv("GOOGLE_AUTH_URI"),
		TokenURI:                os.Getenv("GOOGLE_TOKEN_URI"),
		AuthProviderX509CertURL: os.Getenv("GOOGLE_AUTH_PROVIDER"),
		ClientX509CertURL:       os.Getenv("GOOGLE_CLIENT_CERT_URL"),
	}
	sv := pubsubrouter.NewServer(context.Background(), cfg)
}

Setup Handler

func handlerMessage() HandlerFunc {
	return func(m *pubsubrouter.Message) error error {
		fmt.Println("FROM EVENT:> ", string(m.Data))
		return nil
	}
}

func handlerMessage2() HandlerFunc {
	return func(m *pubsubrouter.Message) error {
		fmt.Println("FROM TEST:> ", string(m.Data))
		return nil
	}
}

Setup Router and Handler

	// add router
	rtr := pubsubrouter.NewRouter()
	
	// setup routing and handler
	rtr.Handle("/event", handlerMessage())
	rtr.Handle("/test", handlerMessage2())

Starting Subscriber

	sv.Subscribe(os.Getenv("EVENT_BROKER_SERIAL"), rtr).Start()

Starting Publisher

Send event with attribute path

	sv.Publish(os.Getenv("EVENT_BROKER_SERIAL"), "/test", "Message send test")

Example

For best model example check example folder

go run example/main.go

About

Route your action in gcp Pubsub easy

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy