Skip to content

Commit

Permalink
[FAB-8768] Option for block events in InfraProvider
Browse files Browse the repository at this point in the history
Added options in InfraProvider that are passed to
the event client. A custom ProviderFactory may be
created to pass in those options.

Change-Id: I62d10b26b552cee4c6b44e53986df832cb3a9994
Signed-off-by: Bob Stasyszyn <Bob.Stasyszyn@securekey.com>
  • Loading branch information
bstasyszyn committed Mar 10, 2018
1 parent aec90b3 commit 69d7191
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pkg/fab/events/eventhubclient/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ type params struct {

func defaultParams() *params {
return &params{
connProvider: ehConnProvider,
interests: filteredBlockInterests,
respTimeout: 5 * time.Second,
connProvider: ehConnProvider,
interests: blockInterests,
respTimeout: 5 * time.Second,
permitBlockEvents: true,
}
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/fabsdk/provider/fabpvdr/fabpvdr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package fabpvdr
import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/context"
"github.com/hyperledger/fabric-sdk-go/pkg/common/lazycache"
"github.com/hyperledger/fabric-sdk-go/pkg/common/options"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/fab"
channelImpl "github.com/hyperledger/fabric-sdk-go/pkg/fab/channel"
Expand Down Expand Up @@ -50,7 +51,7 @@ type fabContext struct {
}

// New creates a InfraProvider enabling access to core Fabric objects and functionality.
func New(config core.Config) *InfraProvider {
func New(config core.Config, opts ...options.Opt) *InfraProvider {
idleTime := config.TimeoutOrDefault(core.ConnectionIdle)
sweepTime := config.TimeoutOrDefault(core.CacheSweepInterval)
eventIdleTime := config.TimeoutOrDefault(core.EventServiceIdle)
Expand All @@ -66,7 +67,7 @@ func New(config core.Config) *InfraProvider {
return NewEventClientRef(
eventIdleTime,
func() (fab.EventClient, error) {
return getEventClient(cacheKey.Context(), cacheKey.ChannelConfig())
return getEventClient(cacheKey.Context(), cacheKey.ChannelConfig(), opts...)
},
), nil
},
Expand Down Expand Up @@ -188,16 +189,15 @@ func (f *InfraProvider) CreateOrdererFromConfig(cfg *core.OrdererConfig) (fab.Or
return newOrderer, nil
}

func getEventClient(ctx context.Client, chConfig fab.ChannelCfg) (fab.EventClient, error) {
func getEventClient(ctx context.Client, chConfig fab.ChannelCfg, opts ...options.Opt) (fab.EventClient, error) {
// TODO: This logic should be based on the channel capabilities. For now,
// look at the EventServiceType specified in the config file.
switch ctx.Config().EventServiceType() {
case core.DeliverEventServiceType:
logger.Debugf("Using deliver events")
return deliverclient.New(ctx, chConfig)
return deliverclient.New(ctx, chConfig, opts...)
case core.EventHubEventServiceType:
logger.Debugf("Using event hub events")
return eventhubclient.New(ctx, chConfig, eventhubclient.WithBlockEvents())
return eventhubclient.New(ctx, chConfig, opts...)
default:
return nil, errors.Errorf("unsupported event service type: %d", ctx.Config().EventServiceType())
}
Expand Down

0 comments on commit 69d7191

Please sign in to comment.