This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Singularize queue and exchange structures
- Loading branch information
Showing
5 changed files
with
134 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package amqp | ||
|
||
import ( | ||
amqpDriver "github.com/streadway/amqp" | ||
) | ||
|
||
type Channels struct { | ||
Version string | ||
Connection *amqpDriver.Connection | ||
} | ||
|
||
type ChannelOptions struct { | ||
ConnectionUrl string | ||
} | ||
|
||
type ChannelDeclareOptions struct { | ||
Name string | ||
Kind string | ||
Durable bool | ||
AutoDelete bool | ||
Internal bool | ||
NoWait bool | ||
Args amqpDriver.Table | ||
} | ||
|
||
type ChannelBindOptions struct { | ||
DestinationChannelName string | ||
SourceChannelName string | ||
RoutingKey string | ||
NoWait bool | ||
Args amqpDriver.Table | ||
} | ||
|
||
type ChannelUnindOptions struct { | ||
DestinationChannelName string | ||
SourceChannelName string | ||
RoutingKey string | ||
NoWait bool | ||
Args amqpDriver.Table | ||
} | ||
|
||
func (Channels *Channels) Declare(options ChannelDeclareOptions) error { | ||
ch, err := Channels.Connection.Channel() | ||
if err != nil { | ||
return err | ||
} | ||
defer ch.Close() | ||
return ch.ChannelDeclare( | ||
options.Name, | ||
options.Kind, | ||
options.Durable, | ||
options.AutoDelete, | ||
options.Internal, | ||
options.NoWait, | ||
options.Args, | ||
) | ||
} | ||
|
||
func (Channels *Channels) Delete(name string) error { | ||
ch, err := Channels.Connection.Channel() | ||
if err != nil { | ||
return err | ||
} | ||
defer ch.Close() | ||
return ch.ChannelDelete( | ||
name, | ||
false, // ifUnused | ||
false, // noWait | ||
) | ||
} | ||
|
||
func (Channels *Channels) Bind(options ChannelBindOptions) error { | ||
ch, err := Channels.Connection.Channel() | ||
if err != nil { | ||
return err | ||
} | ||
defer ch.Close() | ||
return ch.ChannelBind( | ||
options.DestinationChannelName, | ||
options.RoutingKey, | ||
options.SourceChannelName, | ||
options.NoWait, | ||
options.Args, | ||
) | ||
} | ||
|
||
func (Channels *Channels) Unbind(options ChannelUnindOptions) error { | ||
ch, err := Channels.Connection.Channel() | ||
if err != nil { | ||
return err | ||
} | ||
defer ch.Close() | ||
return ch.ChannelUnbind( | ||
options.DestinationChannelName, | ||
options.RoutingKey, | ||
options.SourceChannelName, | ||
options.NoWait, | ||
options.Args, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters