Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/firebase realtime database #724

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@
<artifactId>quarkus-google-cloud-firebase-devservices-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase-realtime-database</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase-realtime-database-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firestore</artifactId>
Expand Down
76 changes: 76 additions & 0 deletions docs/modules/ROOT/pages/firebase-database.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
= Google Cloud Services - Firebase Admin

This extension allows to inject a `com.google.cloud.firestore.Firestore` object inside your Quarkus application.

This extension will pickup on any available `com.google.firebase.FirebaseApp` (see https://quarkiverse.github.io/quarkiverse-docs/quarkus-google-cloud-services/main/firebase-admin.html[Firebase Admin extension] for more info) to configure the Realtime Database.

Be sure to have read the https://quarkiverse.github.io/quarkiverse-docs/quarkus-google-cloud-services/main/index.html[Google Cloud Services extension pack global documentation] before this one, it contains general configuration and information.

== Bootstrapping the project

First, we need a new project. Create a new project with the following command (replace the version placeholder with the correct one):

[source, shell script]
----
mvn io.quarkus:quarkus-maven-plugin:${quarkusVersion}:create \
-DprojectGroupId=org.acme \
-DprojectArtifactId=firebase-admin-quickstart \
-Dextensions="resteasy-reactive-jackson,quarkus-google-cloud-firebase-realtime-database"
cd firebase-admin-quickstart
----

This command generates a Maven project, importing the Google Cloud Firebase Realtime Database extension.)

If you already have your Quarkus project configured, you can add the `quarkus-google-cloud-firebase-realtime-database` extension to your project by running the following command in your project base directory:

[source, shell script]
----
./mvnw quarkus:add-extension -Dextensions="quarkus-google-cloud-firebase-realtime-database"
----

This will add the following to your pom.xml:

[source, xml]
----
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase-realtime-database</artifactId>
</dependency>
----

== Some example

This is an example usage of the extension: we create a REST resource with a single endpoint that creates a 'persons' collection, inserts three persons in it, then search for persons with last name Doe and returns them.

[source,java]
----
import javax.inject.Inject;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;

import com.google.firebase.database.FirebaseDatabase;

@Path("/database")
public class RealtimeDatabaseResource {

@Inject
FirebaseDatabase database; // Inject database

@POST
@Consumes(MediaType.TEXT_PLAIN)
public void database(String data) {
var dbRef = firebaseDatabase.getReference("test");
dbRef.setValueAsync(fields);
}
}
----

== Dev Service

This extension uses the https://quarkiverse.github.io/quarkiverse-docs/quarkus-google-cloud-services/main/firebase-devservices.html[Firebase Devservices] extension to provide a Dev Service. Refer the documentation of this extension for more info.

== Configuration Reference

include::./includes/quarkus-google-cloud-firebase-realtime-database.adoc[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[.configuration-legend]
icon:lock[title=Fixed at build time] Configuration property fixed at build time - All other configuration properties are overridable at runtime
[.configuration-reference.searchable, cols="80,.^10,.^10"]
|===

h|[.header-title]##Configuration property##
h|Type
h|Default

a| [[quarkus-google-cloud-firebase-realtime-database_quarkus-google-cloud-firebase-database-host-override]] [.property-path]##link:#quarkus-google-cloud-firebase-realtime-database_quarkus-google-cloud-firebase-database-host-override[`quarkus.google.cloud.firebase.database.host-override`]##

[.description]
--
Overrides the default service host. This is most commonly used for development or testing activities with a local Firebase Realtime Database emulator instance.


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_GOOGLE_CLOUD_FIREBASE_DATABASE_HOST_OVERRIDE+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_GOOGLE_CLOUD_FIREBASE_DATABASE_HOST_OVERRIDE+++`
endif::add-copy-button-to-env-var[]
--
|string
|

|===

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[.configuration-legend]
icon:lock[title=Fixed at build time] Configuration property fixed at build time - All other configuration properties are overridable at runtime
[.configuration-reference.searchable, cols="80,.^10,.^10"]
|===

h|[.header-title]##Configuration property##
h|Type
h|Default

a| [[quarkus-google-cloud-firebase-realtime-database_quarkus-google-cloud-firebase-database-host-override]] [.property-path]##link:#quarkus-google-cloud-firebase-realtime-database_quarkus-google-cloud-firebase-database-host-override[`quarkus.google.cloud.firebase.database.host-override`]##

[.description]
--
Overrides the default service host. This is most commonly used for development or testing activities with a local Firebase Realtime Database emulator instance.


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_GOOGLE_CLOUD_FIREBASE_DATABASE_HOST_OVERRIDE+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_GOOGLE_CLOUD_FIREBASE_DATABASE_HOST_OVERRIDE+++`
endif::add-copy-button-to-env-var[]
--
|string
|

|===

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class FirebaseDevServiceProcessor {
FirebaseEmulatorContainer.Emulator.FIREBASE_HOSTING, "quarkus.google.cloud.firebase.hosting.emulator-host",
FirebaseEmulatorContainer.Emulator.CLOUD_FUNCTIONS, "quarkus.google.cloud.functions.emulator-host",
FirebaseEmulatorContainer.Emulator.EVENT_ARC, "quarkus.google.cloud.eventarc.emulator-host",
FirebaseEmulatorContainer.Emulator.REALTIME_DATABASE, "quarkus.google.cloud.database.emulator-host",
FirebaseEmulatorContainer.Emulator.REALTIME_DATABASE, "quarkus.google.cloud.firebase.database.host-override",
FirebaseEmulatorContainer.Emulator.CLOUD_FIRESTORE, "quarkus.google.cloud.firestore.host-override",
FirebaseEmulatorContainer.Emulator.CLOUD_STORAGE, "quarkus.google.cloud.storage.host-override",
FirebaseEmulatorContainer.Emulator.PUB_SUB, "quarkus.google.cloud.pubsub.emulator-host");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,10 @@ private void writeOutputFrame(OutputFrame frame, Level level) {
}

private String getEmulatorEndpoint(Emulator emulator) {
return this.getHost() + ":" + emulatorPort(emulator);
var endpoint = this.getHost() + ":" + emulatorPort(emulator);
if (emulator.equals(Emulator.REALTIME_DATABASE)) {
endpoint = "http://" + endpoint;
}
return endpoint;
}
}
71 changes: 71 additions & 0 deletions firebase-realtime-database/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase-devservices-parent</artifactId>
<version>2.14.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-google-cloud-firebase-realtime-database-deployment</artifactId>
<name>Quarkus - Google Cloud Services - Firebase Realtime Database - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase-realtime-database</artifactId>
</dependency>
<!-- Needed as Firebase Database depends on Firebase App -->
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase-admin</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase-admin-deployment</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-common-grpc</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkiverse.googlecloudservices.firebase.database.deployment;

import io.quarkiverse.googlecloudservices.firebase.database.FirebaseDatabaseProducer;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;

public class FirebaseDatabaseBuildSteps {

private static final String FEATURE = "google-cloud-firebase-realtime-database";

@BuildStep
public FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
public AdditionalBeanBuildItem producer() {
return new AdditionalBeanBuildItem(FirebaseDatabaseProducer.class);
}

}
20 changes: 20 additions & 0 deletions firebase-realtime-database/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-services-parent</artifactId>
<version>2.14.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-google-cloud-firebase-realtime-database-parent</artifactId>
<name>Quarkus - Google Cloud Services - Firebas Realtime Database</name>
<packaging>pom</packaging>

<modules>
<module>runtime</module>
<module>deployment</module>
</modules>

</project>
60 changes: 60 additions & 0 deletions firebase-realtime-database/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase-realtime-database-parent</artifactId>
<version>2.14.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-google-cloud-firebase-realtime-database</artifactId>
<name>Quarkus - Google Cloud Services - Firebase Realtime Database - Runtime</name>
<description>Use Google Cloud Firebase</description>

<dependencies>
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-common</artifactId>
</dependency>
<!-- Needed as Firebase Database depends on Firebase App -->
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase-admin</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>extension-descriptor</goal>
</goals>
<phase>compile</phase>
<configuration>
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}
</deployment>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkiverse.googlecloudservices.firebase.database;

import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;

/**
* Root configuration class for Google Cloud Firebase Realtime database setup.
*
*/
@ConfigMapping(prefix = "quarkus.google.cloud.firebase.database")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface FirebaseDatabaseConfig {

/**
* Overrides the default service host.
* This is most commonly used for development or testing activities with a local Firebase Realtime Database emulator
* instance.
*/
Optional<String> hostOverride();

}
Loading
Loading