Temporal is a distributed, scalable, durable, and highly available orchestration engine used to execute asynchronous, long-running business logic in a scalable and resilient way.
π Jump to:
The Temporal Swift SDK provides a package for building distributed, durable workflows and activities using Swift's modern concurrency features. Temporal enables you to build reliable applications that recover from failures, scale dynamically, and maintain long-running business processes with confidence.
Key Features:
@Workflow and @Activity macros to avoid
boilerplateThe Temporal Swift SDK excels in scenarios requiring reliable, long-running business processes such as:
π E-commerce & Payment Processing
π Data Processing & ETL
π’ Business Process Automation
π Monitoring & Operations
To install/upgrade Swift, see https://www.swift.org/install/
To use the Swift Temporal SDK in your Swift project, add it as a dependency in
your Package.swift file:
dependencies: [
.package(url: "https://github.com/apple/swift-temporal-sdk.git", .upToNextMinor(from: "0.6.0"))
]
Clone the repository
git clone git@github.com:apple/swift-temporal-sdk.git
Build the package
swift build
Run tests
swift test
Run an example
# Install Temporal CLI from https://temporal.io/setup/install-temporal-cli
temporal server start-dev
cd Examples/Greeting
swift run GreetingExample
Here's a simple example showing how to create a workflow and activity:
import GRPCNIOTransportHTTP2Posix
import Logging
import Temporal
// Define an activity
@ActivityContainer
struct GreetingActivities {
@Activity
func sayHello(input: String) -> String {
"Hello, \(input)!"
}
}
// Define a workflow
@Workflow
struct GreetingWorkflow {
mutating func run(context: WorkflowContext<Self>, input: String) async throws -> String {
let greeting = try await context.executeActivity(
GreetingActivities.Activities.SayHello.self,
options: ActivityOptions(startToCloseTimeout: .seconds(30)),
input: input
)
return greeting
}
}
// Create worker and client
@main
struct MyApp {
static func main() async throws {
let worker = try TemporalWorker(
configuration: .init(
namespace: "default",
taskQueue: "greeting-queue",
instrumentation: .init(serverHostname: "127.0.0.1")
),
target: .ipv4(address: "127.0.0.1", port: 7233),
transportSecurity: .plaintext,
activityContainers: GreetingActivities(),
workflows: [GreetingWorkflow.self],
logger: Logger(label: "worker")
)
let client = try TemporalClient(
target: .ipv4(address: "127.0.0.1", port: 7233),
transportSecurity: .plaintext,
configuration: .init(instrumentation: .init(serverHostname: "127.0.0.1")),
logger: Logger(label: "client")
)
try await withThrowingTaskGroup { group in
group.addTask {
try await worker.run()
}
group.addTask {
try await client.run()
}
// Wait for the worker and client to run
try await Task.sleep(for: .seconds(1))
// Execute workflow
print("Executing workflow")
let result = try await client.executeWorkflow(
type: GreetingWorkflow.self,
options: .init(id: "greeting-1", taskQueue: "greeting-queue"),
input: "World"
)
print(result) // "Hello, World!"
// Cancel the client and worker
group.cancelAll()
}
}
}
mainIf you have any questions or need help, feel free to reach out by opening an issue.
Swift
99.9%
Temporal is a distributed, scalable, durable, and highly available orchestration engine used to execute asynchronous, long-running business logic in a scalable and resilient way.
π Jump to:
The Temporal Swift SDK provides a package for building distributed, durable workflows and activities using Swift's modern concurrency features. Temporal enables you to build reliable applications that recover from failures, scale dynamically, and maintain long-running business processes with confidence.
Key Features:
@Workflow and @Activity macros to avoid
boilerplateThe Temporal Swift SDK excels in scenarios requiring reliable, long-running business processes such as:
π E-commerce & Payment Processing
π Data Processing & ETL
π’ Business Process Automation
π Monitoring & Operations
To install/upgrade Swift, see https://www.swift.org/install/
To use the Swift Temporal SDK in your Swift project, add it as a dependency in
your Package.swift file:
dependencies: [
.package(url: "https://github.com/apple/swift-temporal-sdk.git", .upToNextMinor(from: "0.6.0"))
]
Clone the repository
git clone git@github.com:apple/swift-temporal-sdk.git
Build the package
swift build
Run tests
swift test
Run an example
# Install Temporal CLI from https://temporal.io/setup/install-temporal-cli
temporal server start-dev
cd Examples/Greeting
swift run GreetingExample
Here's a simple example showing how to create a workflow and activity:
import GRPCNIOTransportHTTP2Posix
import Logging
import Temporal
// Define an activity
@ActivityContainer
struct GreetingActivities {
@Activity
func sayHello(input: String) -> String {
"Hello, \(input)!"
}
}
// Define a workflow
@Workflow
struct GreetingWorkflow {
mutating func run(context: WorkflowContext<Self>, input: String) async throws -> String {
let greeting = try await context.executeActivity(
GreetingActivities.Activities.SayHello.self,
options: ActivityOptions(startToCloseTimeout: .seconds(30)),
input: input
)
return greeting
}
}
// Create worker and client
@main
struct MyApp {
static func main() async throws {
let worker = try TemporalWorker(
configuration: .init(
namespace: "default",
taskQueue: "greeting-queue",
instrumentation: .init(serverHostname: "127.0.0.1")
),
target: .ipv4(address: "127.0.0.1", port: 7233),
transportSecurity: .plaintext,
activityContainers: GreetingActivities(),
workflows: [GreetingWorkflow.self],
logger: Logger(label: "worker")
)
let client = try TemporalClient(
target: .ipv4(address: "127.0.0.1", port: 7233),
transportSecurity: .plaintext,
configuration: .init(instrumentation: .init(serverHostname: "127.0.0.1")),
logger: Logger(label: "client")
)
try await withThrowingTaskGroup { group in
group.addTask {
try await worker.run()
}
group.addTask {
try await client.run()
}
// Wait for the worker and client to run
try await Task.sleep(for: .seconds(1))
// Execute workflow
print("Executing workflow")
let result = try await client.executeWorkflow(
type: GreetingWorkflow.self,
options: .init(id: "greeting-1", taskQueue: "greeting-queue"),
input: "World"
)
print(result) // "Hello, World!"
// Cancel the client and worker
group.cancelAll()
}
}
}
mainIf you have any questions or need help, feel free to reach out by opening an issue.
Swift
99.9%