Giter Club home page Giter Club logo

cloud-pubsub's Introduction

cloud-pubsub

Provides methods to consume messages from Google PubSub using Futures and Hyper.

Authentication

Authentication is provided by rust-goauth. The BaseClient expects to receive the path to the file containing your Google Cloud service account JSON key.

Token Renewal

The JWT token has a short life time and needs to be renewed periodically for long lived processes.

There is a provided helper which will renew the token every 15 mins:

let pubsub = match BaseClient::create(config.google_application_credentials) {
    Err(e) => panic!("Failed to initialize pubsub: {}", e),
        Ok(p) => p,
};

tokio::run(lazy(move || {
    pubsub.spawn_token_renew();
}))

Env Config

Envy is an excellent way to load your config.

#[derive(Deserialize)]
struct Config {
    pubsub_subscription: String,
    google_application_credentials: String,
}


fn main() {
    let parsed_env = envy::from_env::<Config>();
    if let Err(e) = parsed_env {
        eprintln!("ENV is not valid: {}", e);
        std::process::exit(1);
    }
    let config = parsed_env.unwrap();

    let pubsub = match BaseClient::create(config.google_application_credentials) {
        Err(e) => panic!("Failed to initialize pubsub: {}", e),
        Ok(p) => p,
    };
}

Log Config

In order to produce log output, executables have to use a logger implementation compatible with the log facade. There are many available implementations to chose from, for example:

env_logger is an excellent way to log in your executables.

[dependencies]
log = "0.4"
env_logger = "0.7"
fn main() {
    env_logger::init();

    info!("starting up");

    // ...
}

Subscribing

Connecting to existing subscription

let sub = my_client.subscribe("subscription-name")

Subscribing to a topic

When subscribing to a topic, a random subscription name will be generated. To prevent dangling subscriptions, you need to explicitly call subscription.destroy().

cloud-pubsub's People

Contributors

bruceg avatar kayleg avatar ruseinov avatar sync avatar tehanswer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.