You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> The complete example for extending and embedding Spin [can be found on GitHub](https://github.com/fermyon/spin/tree/main/examples/spin-timer-echo).
8
+
> The complete example for extending and embedding Spin [can be found on GitHub](https://github.com/fermyon/spin/tree/main/examples/spin-timer).
9
9
10
10
Spin currently implements triggers and application models for:
11
11
@@ -20,36 +20,41 @@ In this document we will explore how to extend Spin with custom event sources
20
20
(triggers) and application models built on top of the WebAssembly component
21
21
model, as well as how to embed Spin in your application.
22
22
23
-
The current application types that can be implemented with Spin have entrypoints
23
+
In this article we will build a Spin trigger to run the applications based on a
24
+
timer, executing Spin components at configured time interval.
25
+
26
+
The current application types that can be implemented with Spin have entry points
and it handles taking the Wasmtime pre-instantiated module, mapping all the
110
118
component files, environment variables, and allowed HTTP domains, populating
111
119
the Wasmtime store with the appropriate data, and returning the store and instance.
112
-
- invoking the entrypoint `echo` is done in this example in a new Tokio thread —
120
+
- invoking the entry point `handle-timer-request` is done in this example in a new Tokio thread —
113
121
this is an implementation choice based on the needs of the trigger.
114
122
- the return value from the component (a string in this example) can then be
115
123
used — in the case of the HTTP trigger, this is an HTTP response, which is then
@@ -119,13 +127,55 @@ This is very similar to how the [HTTP](/http-trigger) and [Redis](/redis-trigger
119
127
triggers are implemented, and it is the recommended way to extend Spin with your
120
128
own trigger and application model.
121
129
130
+
Writing components for the new trigger can be done by using the
131
+
[`wit-bindgen` tooling](https://github.com/bytecodealliance/wit-bindgen) from
132
+
Rust and other supported languages (see [the example in Rust](https://github.com/fermyon/spin/tree/main/examples/spin-timer/example)):
133
+
134
+
```rust
135
+
// automatically generate Rust bindings that help us implement the
136
+
// `handle-timer-request` function that the trigger will execute.
137
+
wit_bindgen_rust::export!("../spin-timer.wit");
138
+
...
139
+
fnhandle_timer_request(msg:String) ->String {
140
+
format!("ECHO: {}", msg)
141
+
}
142
+
```
143
+
144
+
Components can be compiled to WebAssembly, then used from a `spin.toml`
145
+
application configuration.
146
+
122
147
Embedding the new trigger in a Rust application is done by creating a new trigger
123
148
instance, then calling its `run` function:
124
149
125
150
```rust
151
+
// app() is a utility function that generates a complete application configuration.
> This document is continuously evolving as we improve language SDKs and add
9
+
> more examples on how to build Spin components in various programming languages.
10
+
11
+
> See the document on writing [Rust](/rust-components) and [Go](/go-components)
12
+
> components for Spin for detailed guides.
13
+
14
+
WebAssembly is becoming [a popular compilation target for programming languages](https://www.fermyon.com/wasm-languages/webassembly-language-support), and as language toolchains add support for the
0 commit comments