MyNixOS website logo
Description

GCP Pub/Sub Client for Haskell.

GCP Pub/Sub topic and subscription client for Haskell.

google-cloud-pubsub

A thin wrapper around Google Cloud Pub/Sub for Haskell.

Features

Topic Operations

  • Create topics
  • Delete topics
  • Publish messages to topics

Subscription Operations

  • Create subscriptions
  • Delete subscriptions
  • Acknowledge messages
  • Modify acknowledgment deadlines
  • Pull messages from subscriptions

Installation

  • Cabal: add to your .cabal
    • build-depends: google-cloud-pubsub == 1.1.0.0
  • Stack: add to your package.yaml
    • dependencies: - google-cloud-pubsub == 1.1.0.0

This package depends on google-cloud-common for authentication and HTTP helpers.

Usage

Topic Operations

import Google.Cloud.PubSub.Topic

-- Create a topic
result <- createTopic "my-project" "my-topic"
case result of
  Left err -> putStrLn $ "Error: " ++ err
  Right topic -> print topic

-- Publish a message
let message = Message "Hello World" Nothing Nothing
publishResult <- publishMessage "my-project" "my-topic" [message]
case publishResult of
  Left err -> putStrLn $ "Error: " ++ err
  Right response -> print $ messageIds response

-- Delete a topic
deleteResult <- deleteTopic "my-project" "my-topic"
case deleteResult of
  Left err -> putStrLn $ "Error: " ++ err
  Right _ -> putStrLn "Topic deleted successfully"

Subscription Operations

import Google.Cloud.PubSub.Subscription

-- Create a subscription
let config = SubscriptionConfig 
  { topic = "projects/my-project/topics/my-topic"
  , pushConfig = Nothing
  , ackDeadlineSeconds = 600
  , retainAckedMessages = False
  , messageRetentionDuration = Nothing
  , labels = Nothing
  , enableMessageOrdering = False
  , expirationPolicy = Nothing
  , filter = Nothing
  , deadLetterPolicy = Nothing
  , retryPolicy = Nothing
  , enableExactlyOnceDelivery = Nothing
  }

createResult <- createSubscription "my-project" "my-subscription" config
case createResult of
  Left err -> putStrLn $ "Error: " ++ err
  Right subscription -> print subscription

-- Pull messages
pullResult <- pullMessages "my-project" "my-subscription" 10
case pullResult of
  Left err -> putStrLn $ "Error: " ++ err
  Right response -> do
    mapM_ print $ receivedMessages response
    -- Acknowledge messages
    let ackIds = map ackId $ receivedMessages response
    ackResult <- acknowledgeMessages "my-project" "my-subscription" ackIds
    case ackResult of
      Left err -> putStrLn $ "Ack error: " ++ err
      Right _ -> putStrLn "Messages acknowledged"

-- Delete a subscription
deleteResult <- deleteSubscription "my-project" "my-subscription"
case deleteResult of
  Left err -> putStrLn $ "Error: " ++ err
  Right _ -> putStrLn "Subscription deleted successfully"

Authentication

Authentication is handled by google-cloud-common and follows this order:

  1. If GOOGLE_APPLICATION_CREDENTIALS is set, a Service Account JSON is used to create a signed JWT which is exchanged for an access token.
  2. Otherwise, the Compute metadata server is used (suitable for GCE/GKE).

Dependencies

  • google-cloud-common - Common functionality for Google Cloud libraries

License

MIT © Contributors.

Metadata

Version

1.1.0.0

License

Platforms (76)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows