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

Improve readme and add oss requirements #30

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions CODE-OF-CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Community Code of Conduct

The NATS Swift follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md).
38 changes: 38 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Contributing

Thanks for your interest in contributing! This document contains `nats-io/nats.swift` specific contributing details. If you are a first-time contributor, please refer to the general [NATS Contributor Guide](https://nats.io/contributing/) to get a comprehensive overview of contributing to the NATS project.

## Getting started

There are there general ways you can contribute to this repo:
Jarema marked this conversation as resolved.
Show resolved Hide resolved

- Proposing an enhancement or new feature
- Reporting a bug or regression
- Contributing changes to the source code

For the first two, refer to the [GitHub Issues](https://github.com/nats-io/nats.swift/issues/new/choose) which guides you through the available options along with the needed information to collect.

## Contributing Changes

_Prior to opening a pull request, it is recommended to open an issue first to ensure the maintainers can review intended changes. Exceptions to this rule include fixing non-functional source such as code comments, documentation or other supporting files._

Proposing source code changes is done through GitHub's standard pull request workflow.

If your branch is a work-in-progress then please start by creating your pull requests as draft, by clicking the down-arrow next to the `Create pull request` button and instead selecting `Create draft pull request`.

This will defer the automatic process of requesting a review from the NATS Swift team and significantly reduces noise until you are ready. Once you are happy with your PR, you can click the `Ready for review` button.

### Guidelines

A good pull request includes:

- A high-level description of the changes, including links to any issues that are related by adding comments like `Resolves #NNN` to your description. See [Linking a Pull Request to an Issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) for more information.
- An up-to-date parent commit. Please make sure you are pulling in the latest `main` branch and rebasing your work on top of it, i.e. `git rebase main`.
- Unit tests where appropriate. Bug fixes will benefit from the addition of regression tests. New features will not be accepted without suitable test coverage!
- No more commits than necessary. Sometimes having multiple commits is useful for telling a story or isolating changes from one another, but please squash down any unnecessary commits that may just be for clean-up, comments or small changes.
- No additional external dependencies that aren't absolutely essential. Please do everything you can to avoid pulling in additional libraries/dependencies as we will be very critical of these.

## Get Help

If you have questions about the contribution process, please start a [GitHub discussion](https://github.com/nats-io/nats.swift/discussions), join the [NATS Slack](https://slack.nats.io/), or send your question to the [NATS Google Group](https://groups.google.com/forum/#!forum/natsio).

124 changes: 17 additions & 107 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

**:warning: WARNING: THIS REPOSITORY IS UNDER REWORK AND SHOULD NOT BE USED AT THE MOMENT :warning: **
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**:warning: WARNING: THIS REPOSITORY IS UNDER REWORK AND SHOULD NOT BE USED AT THE MOMENT :warning: **
#### :warning: WARNING: THIS REPOSITORY IS UNDER REWORK AND SHOULD NOT BE USED AT THE MOMENT :warning:

** isn't rendering


Tested with Swift 5.4 on [![macos](https://github.com/aus-der-Technik/swifty-nats/actions/workflows/macos.yml/badge.svg?branch=main)](https://github.com/aus-der-Technik/swifty-nats/actions/workflows/macos.yml) and [![Linux](https://github.com/aus-der-Technik/swifty-nats/actions/workflows/linux.yml/badge.svg?branch=main)](https://github.com/aus-der-Technik/swifty-nats/actions/workflows/linux.yml)

Swift Version Compatibility: [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Faus-der-Technik%2Fswifty-nats%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/aus-der-Technik/swifty-nats)

Platform Compatibility: [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Faus-der-Technik%2Fswifty-nats%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/aus-der-Technik/swifty-nats)

## Support
Expand All @@ -23,7 +20,7 @@ We'll do our best to help quickly. You can also just drop by and say hello. We'r
Add this packages as a dependency in your projects `Package.swift` file and add the Name to your target like shown in this example:

```swift
// swift-tools-version:5.4
// swift-tools-version:5.6

import PackageDescription

Expand All @@ -33,7 +30,7 @@ let package = Package(
.executable(name: "YourApp", targets: ["YourApp"]),
],
dependencies: [
.package(name: "NatsSwift", url: "https://github.com/aus-der-technik/NatsSwift.git", from: "2.2.0")
.package(name: "NatsSwift", url: "https://github.com/nats-io/NatsSwift.git", from: "0.1")
],
targets: [
.target(
Expand All @@ -46,76 +43,43 @@ let package = Package(
```
### In an .xcodeproj
Open the project inspector in XCode and select your project. It is importent to select the **project** and not a target!
Klick on the third tab `Package Dependencies` and add the git url `https://github.com/aus-der-technik/NatsSwift.git` by selecting the litte `+`-sign at the end of the package list.
Klick on the third tab `Package Dependencies` and add the git url `https://github.com/nats-io/NatsSwift.git` by selecting the litte `+`-sign at the end of the package list.


## Basic Usage
```swift

import NatsSwift

// register a new client
let client = NatsClient("http://nats.server:4222")
// Setup the logger level
logger.logLevel = .debug

// listen to an event
client.on(.connect) { _ in
print("Client connected")
}
// create the client
let client = ClientOptions().url(URL(string: natsServer.clientURL)!).build()

// try to connect to the server
try? client.connect()
// connect to the server
try await client.connect()

// subscribe to a channel with a inline message handler.
client.subscribe("foo.bar") { message in
print("payload: \(message.payload)")
print("size: \(message.byteCount)")
print("reply subject: \(message.replySubject.subject)")
}
// subscribe to a subject
let subscription = try await client.subscribe(to: "events.>")

// publish an event onto the message strem into a subject
client.publish("this event happened", to: "foo.bar")

```
// publish a message
try client.publish("msg".data(using: .utf8)!, subject: "events.example")

for await message in subscriptions {
print( "payload: \(String(data:message.payload!, encoding: .utf8)!)")
}

### Setting the loglevel
The default loglevel is `.error`. You can reset it to see more verbose messages. Possible
Values are `.debug`, `.info`, `.error` or `.critical`

//FIXME: not a proper way to set a logging level from outside the library
```swift
let client = NatsClient("http://nats.server:4222")
client.config.loglevel = .info
```

### Reconnection is up to you
Reconnection is not part of this package, because if a server diconnects your application have to be sure that
subscribtions are made up again correctly.

With NatsSwift this is a very easy step:

```swift

// register a new client
let client = NatsClient(url)

// listen to the .disconnected event to try a reconnect
client.on(.disconnected) { [self] _ in
sleep(5);
try? client.reconnect()
doSubscribe()
}

// subscribe to the channels
doSubscribe()

// private function to subscribe to channels
private func doSubscribe(){
client.subscribe("foo.bar") { message in
print("payload: \(message.payload)")
}
}
```

### List of events
The public class `NatsEvent` contains all events you can subscribt to.

Expand All @@ -130,59 +94,5 @@ The public class `NatsEvent` contains all events you can subscribt to.
| informed | The server sends his information data successfully to the client. |


### Information about the connected server

Since 2.0.2 it is possible to get the informations from the conencted server

```swift
let client = NatsClient("http://nats.server:4222")
print("\(client.serverInformation.serverName) has Version: \(client.serverInformation.version))");
```


## Contribution
Contribution is always welcome. Just send me a pull request.

# Changelog

## 2.2.0
- The client configuration is now publicly available
- The handling of the connection status has been rewritten
- Rewrite of the connection setup
- The connection termination was rewritten
- All classes have been cleaned up (refactoring)
- A new license was added (BSD-0)
- The reconnection code was removed
- Subscription queue is an optional property of NatsSubject

## 2.1.1
- rewrite the ChannelHandler: remove a bug that could lead into dropped messages.

## 2.1.0
- uses NIO2
- works with Vapor, now!

## 2.0.3
- supports iOS anf tvOS

## 2.0.2
- Get information from the connected Server (Version, name, id, ...)

## 2.0.1
- Test with GitHub Actions
- Update Dockerfile to build and test on Swift 5.4 (Linux)
- Test with a real NATS-Server on macos
- Cleanup unused definitions
- Update Informations, do project care

## 2.0.0
- Tested with NATS 2.3.4
- Introduced logging
- Updated depricated functions

# Roadmap
See: Contribution ;)
- Propper function description is needed

# Attribution
This library is based on excellent work in https://github.com/aus-der-Technik/NatsSwift
Loading