github encoredev/encore v1.3.0
Introducing Encore PubSub

latest releases: v1.4.0, v1.3.1
2 years ago

We're excited to share Encore's world-class developer experience now extends to asynchronous event processing with the addition of Encore PubSub!

Pub/Sub is one of the core building blocks of modern distributed systems. This means you can now easily:

  • Effortlessly build event driven backend applications
  • Off-load expensive business logic into the background and not during request processing
  • Process queues of work in a reliable, scalable, and cloud-agnostic way
  • Decouple systems from each other

Building such applications typically involves endless repetition and tedious boilerplate. No more.

Run encore version update to grab the latest version and experience it for yourself!

— If you're new to Encore, check out the Quick Start Guide to get started building.

Encore PubSub

Encore PubSub takes the same approach to building distributed systems as the rest of Encore, and makes building event-driven, asynchronous a breeze. With Encore you define your topics and subscriptions directly in your backend code, like any other object.

With just a few lines of code we have a serverless backend that scales from zero to hundreds of millions of users, with zero boilerplate and with static type safety. Encore takes care of all the complex, boring parts, so you can focus on building your product:

  • Provisioning and configuring the necessary cloud infrastructure
  • Connecting it all together, generating all the boilerplate code and configuration to use the infrastructure within your backend application
  • Connecting it all together with distributed tracing for effortless observability

The best part of all? It works the same way for local development as well as the major cloud providers. Encore provisions the cloud native infrastructure component for your specific cloud provider of choice, but the code works the same way.

To define a topic and begin publishing messages is just a handful lines of code:

import "encore.dev/pubsub"

type SignupEvent struct {
	Username string
	Email    string
}

var Signups = pubsub.NewTopic[*SignupEvent]("user-signups", pubsub.TopicConfig{
	DeliveryGuarantee: pubsub.AtLeastOnce,
})

// To publish a message:
_, err := Signups.Publish(ctx, &SignupEvent{Username: "jane.doe", Email: "jane@example.org"})

To begin receiving messages is equally simple:

import "encore.dev/pubsub"

var _ = pubsub.NewSubscription(
    user.Signups, "send-welcome-email",
    pubsub.SubscriptionConfig[*user.SignupEvent] {
        Handler: SendWelcomeEmail,
    },
)

func SendWelcomeEmail(ctx context.Context, event *user.SignupEvent) error {
    // .. send email ...
}

Testing PubSub

To complement the new PubSub support Encore now comes with a new et (encore testing) package to simplify testing distributed systems.

We're starting with support for testing PubSub behavior, but over time we plan to expand on it to support easy testing of various distributed system behaviors. Read the package docs for more information.

Bug fixes and other improvements

  • Improved handling of max connections for local development (#300)
  • Improved keep-alive of encore db shell database sessions (#263)
  • Improved error messages for several common Encore syntax errors
  • Added support for customizing GOARCH and the docker base image for encore eject docker (#269)
  • Improved CORS handling for local development (#276, #278, #286)
  • Fixed running encore run before encore auth login on new systems (#299)
  • Fixed rendering of encore.dev/rlog log output when using structured logging of booleans (#308)

Thanks to all our contributors

We rely on the community to improve Encore, and we're overwhelmed by your support and encouragement. Big thanks to @davidmytton, @bscott, @bjaanes and others for your bug reports and feedback!

Join the most pioneering developer community

Developers building with Encore are forward-thinkers working on exciting and innovative products. Join the conversation on Slack to see what's going on, learn from others, and share what you're working on.

What’s next

Over the coming weeks we'll be adding much requested flexibility to the Encore framework, with improved support for things like: middleware, configuration and dependency injection. Vote on your favorite feature on the roadmap
– If you like what's going on, why not give the project a star?

As always, if you have questions or ideas, come tell us on Slack.
We’re excited to hear your feedback! ❤️

Catch you in the cloud,
André & the Encore team

Don't miss a new encore release

NewReleases is sending notifications on new releases.