= Google PubSub Lite Component
:doctitle: Google PubSub Lite
:shortname: google-pubsub-lite
:artifactid: camel-google-pubsub-lite
:description: Send and receive messages to/from Google Cloud Platform PubSub Lite Service.
:since: 4.6
:supportlevel: Stable
:tabs-sync-option:
:component-header: Both producer and consumer are supported
//Manually maintained attributes
:group: Google
:camel-spring-boot-name: google-pubsub-lite

*Since Camel {since}*

*{component-header}*

The Google PubSub Lite component provides access
to https://cloud.google.com/pubsub/[Cloud Pub/Sub Lite Infrastructure] via
the https://github.com/googleapis/java-pubsublite[Google Cloud Pub/Sub Lite Client for Java].

The standard xref:google-pubsub-component.adoc[Google Pub/Sub component] isn't compatible with Pub/Sub Lite service due to API and message model differences.
Please refer to the following links to learn more about these differences:

* https://cloud.google.com/pubsub/docs/overview#lite[Pub/Sub Lite Overview]
* https://cloud.google.com/pubsub/docs/choosing-pubsub-or-lite[Choosing between Pub/Sub or Pub/Sub Lite]

Maven users will need to add the following dependency to their pom.xml
for this component:

[source,xml]
------------------------------------------------------
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-google-pubsub-lite</artifactId>
    <!-- use the same version as your Camel core version -->
    <version>x.x.x</version>
</dependency>
------------------------------------------------------

== URI Format

The Google PubSub Component uses the following URI format:

----
google-pubsub-lite://project-id:location:destinationName?[options]
----

Destination Name can be either a topic or a subscription name.


// component-configure options: START

// component-configure options: END

// component options: START
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
// component options: END

// endpoint options: START

// endpoint options: END

// component headers: START
include::partial$component-endpoint-headers.adoc[]
// component headers: END

== Usage

=== Producer Endpoints

Google PubSub Lite expects the payload to be `byte[]` array, Producer endpoints will send:

* String body as `byte[]` encoded as UTF-8
* `byte[]` body as is
* Everything else will be serialised into a `byte[]` array

A Map set as message header `GooglePubsubConstants.ATTRIBUTES` will be sent as PubSub attributes.

When producing messages set the message header `GooglePubsubConstants.ORDERING_KEY`.
This will be set as the PubSub Lite orderingKey for the message.
You can find more information on https://cloud.google.com/pubsub/lite/docs/publishing#using_ordering_keys[Using ordering keys].

=== Consumer Endpoints

Google PubSub Lite will redeliver the message if it has not been acknowledged within the time period set as a configuration option on the subscription.

The component will acknowledge the message once exchange processing has been completed.

=== Message Body

The consumer endpoint returns the content of the message as `byte[]` - exactly as the underlying system sends it.
It is up for the route to convert/unmarshall the contents.

== Examples

You'll need to provide a connectionFactory to the ActiveMQ Component, to have the following examples working.

=== Producer Example

[source,java]
--------------------------------------------------------------------------------
 from("timer://scheduler?fixedRate=true&period=5s")
            .setBody(simple("Hello World ${date:now:HH:mm:ss.SSS}"))
            .to("google-pubsub-lite:123456789012:europe-west3-a:my-topic-lite")
            .log("Message sent: ${body}");
--------------------------------------------------------------------------------

=== Consumer Example

[source,java]
--------------------------------------------------------------------------------
from("google-pubsub-lite:123456789012:europe-west3-a:my-subscription-lite")
            .log("Message received: ${body}");
--------------------------------------------------------------------------------


include::spring-boot:partial$starter.adoc[]
