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

feat: in-memory pubsub component #329

Merged
merged 2 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion cmd/layotto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package main
import (
"encoding/json"
"fmt"
mock_state "mosn.io/layotto/pkg/mock/components/state"
"os"
"strconv"
"time"

mock_state "mosn.io/layotto/pkg/mock/components/state"

"mosn.io/layotto/components/file/local"

"mosn.io/layotto/components/file/s3/alicloud"
Expand Down Expand Up @@ -54,6 +55,7 @@ import (
"github.com/dapr/components-contrib/pubsub/azure/servicebus"
pubsub_gcp "github.com/dapr/components-contrib/pubsub/gcp/pubsub"
pubsub_hazelcast "github.com/dapr/components-contrib/pubsub/hazelcast"
pubsub_inmemory "github.com/dapr/components-contrib/pubsub/in-memory"
seeflood marked this conversation as resolved.
Show resolved Hide resolved
pubsub_kafka "github.com/dapr/components-contrib/pubsub/kafka"
pubsub_mqtt "github.com/dapr/components-contrib/pubsub/mqtt"
"github.com/dapr/components-contrib/pubsub/natsstreaming"
Expand Down Expand Up @@ -208,6 +210,9 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
pubsub.NewFactory("pulsar", func() dapr_comp_pubsub.PubSub {
return pubsub_pulsar.NewPulsar(loggerForDaprComp)
}),
pubsub.NewFactory("in-memory", func() dapr_comp_pubsub.PubSub {
return pubsub_inmemory.New(loggerForDaprComp)
}),
),
// State
runtime.WithStateFactory(
Expand Down
7 changes: 7 additions & 0 deletions configs/config_in_memory.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
}
}
},
"pub_subs": {
"in-memory": {
"metadata": {
"consumerID": "1"
}
}
},
"app": {
"app_id": "app1",
"grpc_callback_port": 9999
Expand Down
51 changes: 51 additions & 0 deletions demo/pubsub/in-memory/in-memory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2021 Layotto Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package main

import (
"context"
"fmt"

"mosn.io/layotto/sdk/go-sdk/client"
)

const (
topic = "in-memory"
)

func main() {
cli, err := client.NewClient()
if err != nil {
panic(err)
}
testPublish(cli)
cli.Close()
}

func testPublish(cli client.Client) {
data := []byte("hello in-memory pubsub")
err := cli.PublishEvent(context.Background(), "in-memory", topic, data)
if err != nil {
panic(err)
}
fmt.Printf("Published a new event.Topic: %s ,Data: %s \n", topic, data)
return
}

func testSubscribe(cli client.Client) error {
return nil
}