fs2-google-cloud-pubsub


License

License

MIT
Categories

Categories

Google Cloud Container PaaS Providers
GroupId

GroupId

com.github.hyjay
ArtifactId

ArtifactId

fs2-google-cloud-pubsub_2.12
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

fs2-google-cloud-pubsub
fs2-google-cloud-pubsub
Project Organization

Project Organization

com.github.hyjay

Download fs2-google-cloud-pubsub_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.hyjay/fs2-google-cloud-pubsub_2.12/ -->
<dependency>
    <groupId>com.github.hyjay</groupId>
    <artifactId>fs2-google-cloud-pubsub_2.12</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.hyjay/fs2-google-cloud-pubsub_2.12/
implementation 'com.github.hyjay:fs2-google-cloud-pubsub_2.12:0.1.0'
// https://jarcasting.com/artifacts/com.github.hyjay/fs2-google-cloud-pubsub_2.12/
implementation ("com.github.hyjay:fs2-google-cloud-pubsub_2.12:0.1.0")
'com.github.hyjay:fs2-google-cloud-pubsub_2.12:jar:0.1.0'
<dependency org="com.github.hyjay" name="fs2-google-cloud-pubsub_2.12" rev="0.1.0">
  <artifact name="fs2-google-cloud-pubsub_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.hyjay', module='fs2-google-cloud-pubsub_2.12', version='0.1.0')
)
libraryDependencies += "com.github.hyjay" % "fs2-google-cloud-pubsub_2.12" % "0.1.0"
[com.github.hyjay/fs2-google-cloud-pubsub_2.12 "0.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.8
com.google.cloud : google-cloud-pubsub jar 1.55.0
co.fs2 : fs2-io_2.12 jar 1.0.2

test (2)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.5
io.circe : circe-parser_2.12 jar 0.10.1

Project Modules

There are no modules declared in this project.

fs2-google-cloud-pubsub

Build Status Maven Central

A developer-first Google cloud Pub/Sub client in Scala, based on the official Google cloud Java client library.

Getting Started

Publishing messages

With the library you can publish messages to a topic with Publisher which automatically will create the topic for you.

import com.github.hyjay.pubsub.Publisher

val io = for {
  // Create a publisher and the returned IO will idempotently create the topic for you. 
  publisher <- Publisher.create("YOUR_PROJECT_ID", "YOUR_TOPIC")
  messageId <- publisher.publish("Hello, world!".getBytes())
} yield ()

io.unsafeRunSync()

Creating a subscription

With the library you can create subscriptions as simple as it can be.

import com.github.hyjay.pubsub.SubscriptionFunctions

val io = SubscriptionFunctions("YOUR_PROJECT_ID").createSubscription("YOUR_TOPIC", "YOUR_SUBSCRIPTION")

io.unsafeRunSync()

Pulling messages

With the library you can pull messages from a subscription as simple as it can be.

import scala.util.Try
import cats.effect.IO
import com.github.hyjay.pubsub.Subscriber

// Return None for parsing failed messages
def parser(payload: Array[Byte]): Option[String] = Try(new String(payload)).toOption

// Print out parsed messages as strings
def run(message: String): IO[Unit] = IO { println(message) }
 
// Subscriber acknowledges parsing failed messages or messages handled by `run` without an error
// It nacks messages that are parsed but having an error while handling
val printMessages = Subscriber.create("YOUR_PROJECT_ID", "YOUR_SUBSCRIPTION").subscribe(parser)(run)

// The IO ends when pulling stop by any errors.
printMessages.unsafeRunSync()

Dependencies

Add this to your build.sbt:

libraryDependencies += "com.github.hyjay" %% "fs2-google-cloud-pubsub" % Version

Testing

If you want to run the test code in this library, set GOOGLE_APPLICATION_CREDENTIALS envvar to a file location of google application credential json file.
Please note that the test code calls actual Google cloud Pub/Sub APIs.

License

MIT - See LICENSE for more information.

Versions

Version
0.1.0