Introduce "noop" go-micro broker
This introduces a no op broker for go-micro. It is set as the default broker for all ocis http services. To avoid starting the default http broker, which opens an unused random http port. Fixes: https://github.com/owncloud/ocis/issues/3829
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package broker
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"go-micro.dev/v4/broker"
|
||||
)
|
||||
|
||||
type NoOp struct{}
|
||||
|
||||
func (n NoOp) Init(_ ...broker.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n NoOp) Options() broker.Options {
|
||||
return broker.Options{}
|
||||
}
|
||||
|
||||
func (n NoOp) Address() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (n NoOp) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n NoOp) Disconnect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n NoOp) Publish(topic string, m *broker.Message, opts ...broker.PublishOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n NoOp) Subscribe(topic string, h broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
}
|
||||
|
||||
func (n NoOp) String() string {
|
||||
return "NoOp"
|
||||
}
|
||||
|
||||
func NewBroker(_ ...broker.Option) broker.Broker {
|
||||
return &NoOp{}
|
||||
}
|
||||
-3
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
oregistry "github.com/owncloud/ocis/v2/ocis-pkg/registry"
|
||||
"go-micro.dev/v4/broker"
|
||||
"go-micro.dev/v4/registry"
|
||||
)
|
||||
|
||||
@@ -20,7 +19,6 @@ func RegisterGRPCEndpoint(ctx context.Context, serviceID, uuid, addr string, ver
|
||||
}
|
||||
ocisRegistry := oregistry.GetRegistry()
|
||||
|
||||
node.Metadata["broker"] = broker.String()
|
||||
node.Metadata["registry"] = ocisRegistry.String()
|
||||
node.Metadata["server"] = "grpc"
|
||||
node.Metadata["transport"] = "grpc"
|
||||
@@ -76,7 +74,6 @@ func RegisterHTTPEndpoint(ctx context.Context, serviceID, uuid, addr string, ver
|
||||
}
|
||||
ocisRegistry := oregistry.GetRegistry()
|
||||
|
||||
node.Metadata["broker"] = broker.String()
|
||||
node.Metadata["registry"] = ocisRegistry.String()
|
||||
node.Metadata["server"] = "http"
|
||||
node.Metadata["transport"] = "http"
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/broker"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/registry"
|
||||
|
||||
mhttps "github.com/go-micro/plugins/v4/server/http"
|
||||
@@ -18,9 +19,11 @@ type Service struct {
|
||||
|
||||
// NewService initializes a new http service.
|
||||
func NewService(opts ...Option) Service {
|
||||
noopBroker := broker.NoOp{}
|
||||
sopts := newOptions(opts...)
|
||||
wopts := []micro.Option{
|
||||
micro.Server(mhttps.NewServer(server.TLSConfig(sopts.TLSConfig))),
|
||||
micro.Broker(noopBroker),
|
||||
micro.Address(sopts.Address),
|
||||
micro.Name(strings.Join([]string{sopts.Namespace, sopts.Name}, ".")),
|
||||
micro.Version(sopts.Version),
|
||||
|
||||
Reference in New Issue
Block a user