fernandoteixxeira/stark-bank-challenge/spring-cloud-gcp-pubsub

Claude Code and agent skill by fernandoteixxeira/stark-bank-challenge

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when publishing or subscribing to Google Cloud Pub/Sub from a Spring Boot app with the Spring Cloud GCP starter — the autoconfigured PubSubTemplate, message converters, the emulator, BOM/version alignment, and testing. For message/DLQ design see gcp-pubsub.

Install

npx vskill@latest install fernandoteixxeira/stark-bank-challenge/spring-cloud-gcp-pubsub

SKILL.md

The same SKILL.md was published earlier as fernandoteixxeira/stark-bank-challenge/spring-cloud-gcp-pubsub.

Spring Cloud GCP Pub/Sub Starter

The spring-cloud-gcp-starter-pubsub autoconfigures a PubSubTemplate from properties, so you don't build a Publisher/Subscriber by hand. This skill is the wiring; for message contracts, idempotency, and dead-letter design see gcp-pubsub.

Version Alignment

The Spring Cloud GCP line is pinned to a Spring Boot line — mismatches fail in subtle ways. Pick by your Boot version:

Spring BootSpring Cloud GCP
3.2.x, 3.3.x5.x
3.4.x6.x / 7.x
3.5.x8.x

Import the BOM and let it manage the starter version:

xml
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-dependencies</artifactId>
<version>5.12.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>

If you also import Google's libraries-bom (for google-cloud-* clients used directly, e.g. in tests), declare it before spring-cloud-gcp-dependencies: the first import wins for overlapping google-cloud-* versions, so your chosen libraries-bom stays authoritative while the Spring Cloud GCP BOM manages only the spring-cloud-gcp-* artifacts.

Publishing

The starter provides a PubSubTemplate bean. Inject the narrow publish interface if you only publish:

java
public PubSubEventPublisher(PubSubPublisherOperations pubSub, String topic) { ... }
pubSub.publish(topic, payload, attributes).get(); // CompletableFuture<String> messageId
  • publish(topic, payload, Map<String,String> headers) returns a CompletableFuture<String>. Call .get() to block until the broker confirms — that is what makes "published" mean durably accepted, so a caller can answer a retry on failure.
  • The topic is the short name; the project comes from configuration.
  • headers become message attributes — routing/observability a subscriber reads without opening the body.

Serialization: the message converter

Register a PubSubMessageConverter bean and the starter wires it into PubSubTemplate; then you publish the object, not JSON:

java
@Bean
PubSubMessageConverter pubSubMessageConverter(ObjectMapper mapper) {
return new JacksonPubSubMessageConverter(mapper); // object <-> JSON, field by field
}

Use a custom PubSubMessageConverter when the wire body is not a field-by-field serialization of your object — a reshaped envelope, a sealed/polymorphic type, enum wire values, grouped value objects. A custom converter keeps that shaping in the adapter instead of forcing Jackson annotations onto a framework-free domain:

java
public PubsubMessage toPubSubMessage(Object payload, Map<String,String> headers) {
byte[] body = /* your shaping */;
PubsubMessage.Builder m = PubsubMessage.newBuilder().setData(ByteString.copyFrom(body, UTF_8));
if (headers != null) m.putAllAttributes(headers);
return m.build();
}
// publish-only apps can throw UnsupportedOperationException from fromPubSubMessage

The converter does not eliminate the serialization — it relocates it out of the publish call. If a plain Jackson shape is acceptable, the stock converter is zero code.

The emulator

Point the whole client at a local emulator with one property — no credentials, plaintext channel, set up for you:

spring.cloud.gcp.project-id=my-project
spring.cloud.gcp.pubsub.emulator-host=localhost:8085
  • With emulator-host set, the starter uses NoCredentialsProvider and a plaintext channel — the app starts and runs without any GCP credentials. Leave it unset for real Pub/Sub (application-default credentials).
  • This is the starter's property; the google-cloud-pubsub client does not read the PUBSUB_EMULATOR_HOST env var on its own. Relaxed binding still lets you set it from the environment as SPRING_CLOUD_GCP_PUBSUB_EMULATOR_HOST.
  • The emulator holds no topics at start — create the topic (and any subscription) before publishing, e.g. PUT http://host:8085/v1/projects/{p}/topics/{t} over its REST API.

Testing

  • Full context: @SpringBootTest + Testcontainers PubSubEmulatorContainer, and in @DynamicPropertySource set spring.cloud.gcp.pubsub.emulator-host to the container endpoint and spring.cloud.gcp.project-id. The autoconfigured PubSubTemplate then publishes to the emulator; assert what landed by pulling with a SubscriberStub.
  • Adapter in isolation: build the publish template by hand against the emulator, mirroring what autoconfig assembles:
java
DefaultPublisherFactory factory = new DefaultPublisherFactory(() -> PROJECT);
factory.setChannelProvider(channelProvider); // emulator channel
factory.setCredentialsProvider(NoCredentialsProvider.create());
PubSubPublisherTemplate template = new PubSubPublisherTemplate(factory);
template.setMessageConverter(yourConverter);
  • A test ObjectMapper should disable FAIL_ON_UNKNOWN_PROPERTIES if you convert maps to generated models — Spring Boot's autoconfigured mapper already does.

See also: gcp-pubsub (contracts, DLQ, idempotency), testcontainers (emulator container + Docker API version), gcp-cloud-run (deploying the service).

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/fernandoteixxeira/stark-bank-challenge/spring-cloud-gcp-pubsub/badge)](https://verified-skill.com/skills/fernandoteixxeira/stark-bank-challenge/spring-cloud-gcp-pubsub)

Something wrong with this skill or its page? Tell us.