@@ -12,45 +12,38 @@ pub use crate::{
12
12
sqs:: { SqsInputOpts , SqsOutputOpts } ,
13
13
} ;
14
14
15
- #[ derive( Deserialize ) ]
16
- pub struct QueueSenderConfig {
17
- pub name : String ,
18
- pub input : SenderInputOpts ,
19
- #[ serde( default ) ]
20
- pub transformation : Option < TransformationConfig > ,
21
- pub output : SenderOutputOpts ,
22
- }
23
-
24
- impl QueueSenderConfig {
25
- pub fn into_sender_input ( self ) -> Result < Box < dyn SenderInput > , & ' static str > {
26
- // FIXME: see if this check is still needed. String transforms worked for the omniqueue redis receiver, I think?
27
- if matches ! ( self . input, SenderInputOpts :: Redis ( _) )
28
- && self
29
- . transformation
30
- . as_ref ( )
31
- . map ( |t| t. format ( ) != TransformerInputFormat :: Json )
32
- . unwrap_or_default ( )
33
- {
34
- return Err ( "redis only supports json formatted transformations" ) ;
35
- }
36
-
37
- Ok ( Box :: new ( QueueSender :: new (
38
- self . name ,
39
- self . input ,
40
- self . transformation ,
41
- self . output ,
42
- ) ) )
15
+ pub fn into_sender_input (
16
+ name : String ,
17
+ input_opts : QueueInputOpts ,
18
+ transformation : Option < TransformationConfig > ,
19
+ output : SenderOutputOpts ,
20
+ ) -> Result < Box < dyn SenderInput > , & ' static str > {
21
+ // FIXME: see if this check is still needed. String transforms worked for the omniqueue redis receiver, I think?
22
+ if matches ! ( input_opts, QueueInputOpts :: Redis ( _) )
23
+ && transformation
24
+ . as_ref ( )
25
+ . map ( |t| t. format ( ) != TransformerInputFormat :: Json )
26
+ . unwrap_or_default ( )
27
+ {
28
+ return Err ( "redis only supports json formatted transformations" ) ;
43
29
}
30
+
31
+ Ok ( Box :: new ( QueueSender :: new (
32
+ name,
33
+ input_opts,
34
+ transformation,
35
+ output,
36
+ ) ) )
44
37
}
45
38
46
39
pub async fn into_receiver_output (
47
40
name : String ,
48
- opts : ReceiverOutputOpts ,
41
+ opts : QueueOutputOpts ,
49
42
// Annoying to have to pass this, but certain backends (redis) only work with certain transformations (json).
50
43
transformation : Option < & TransformationConfig > ,
51
44
) -> Result < Box < dyn ReceiverOutput > , crate :: Error > {
52
45
// FIXME: see if this check is still needed. String transforms worked for the omniqueue redis receiver, I think?
53
- if matches ! ( opts, ReceiverOutputOpts :: Redis ( _) )
46
+ if matches ! ( opts, QueueOutputOpts :: Redis ( _) )
54
47
&& transformation
55
48
. as_ref ( )
56
49
. map ( |t| t. format ( ) != TransformerInputFormat :: Json )
@@ -68,7 +61,7 @@ pub async fn into_receiver_output(
68
61
// TODO: feature flag the variants, thread the features down through to generic-queue
69
62
#[ derive( Debug , Deserialize ) ]
70
63
#[ serde( tag = "type" , rename_all = "lowercase" ) ]
71
- pub enum SenderInputOpts {
64
+ pub enum QueueInputOpts {
72
65
#[ serde( rename = "gcp-pubsub" ) ]
73
66
GCPPubSub ( GCPPubSubInputOpts ) ,
74
67
RabbitMQ ( RabbitMqInputOpts ) ,
@@ -78,7 +71,7 @@ pub enum SenderInputOpts {
78
71
79
72
#[ derive( Clone , Debug , Deserialize ) ]
80
73
#[ serde( tag = "type" , rename_all = "lowercase" ) ]
81
- pub enum ReceiverOutputOpts {
74
+ pub enum QueueOutputOpts {
82
75
#[ serde( rename = "gcp-pubsub" ) ]
83
76
GCPPubSub ( GCPPubSubOutputOpts ) ,
84
77
RabbitMQ ( RabbitMqOutputOpts ) ,
@@ -92,51 +85,50 @@ mod tests {
92
85
SenderOutputOpts , SvixSenderOutputOpts , TransformationConfig , TransformerInputFormat ,
93
86
} ;
94
87
95
- use super :: { into_receiver_output, QueueSenderConfig } ;
88
+ use super :: { into_receiver_output, into_sender_input } ;
96
89
use crate :: {
97
- config:: { ReceiverOutputOpts , SenderInputOpts } ,
90
+ config:: { QueueInputOpts , QueueOutputOpts } ,
98
91
redis:: { RedisInputOpts , RedisOutputOpts } ,
99
92
} ;
100
93
101
94
// FIXME: can't support raw payload access for redis because it requires JSON internally.
102
95
// Revisit after `omniqueue` adoption.
103
96
#[ test]
104
97
fn redis_sender_with_string_transformation_is_err ( ) {
105
- let cfg = QueueSenderConfig {
106
- name : "redis-with-string-transformation" . to_string ( ) ,
107
- input : SenderInputOpts :: Redis ( RedisInputOpts {
108
- dsn : "" . to_string ( ) ,
109
- max_connections : 0 ,
110
- reinsert_on_nack : false ,
111
- queue_key : "" . to_string ( ) ,
112
- delayed_queue_key : None ,
113
- consumer_group : "" . to_string ( ) ,
114
- consumer_name : "" . to_string ( ) ,
115
- ack_deadline_ms : 2_000 ,
116
- } ) ,
117
- transformation : Some ( TransformationConfig :: Explicit {
98
+ let input_opts = QueueInputOpts :: Redis ( RedisInputOpts {
99
+ dsn : "" . to_string ( ) ,
100
+ max_connections : 0 ,
101
+ reinsert_on_nack : false ,
102
+ queue_key : "" . to_string ( ) ,
103
+ delayed_queue_key : None ,
104
+ consumer_group : "" . to_string ( ) ,
105
+ consumer_name : "" . to_string ( ) ,
106
+ ack_deadline_ms : 2_000 ,
107
+ } ) ;
108
+
109
+ let err = into_sender_input (
110
+ "redis-with-string-transformation" . to_owned ( ) ,
111
+ input_opts,
112
+ Some ( TransformationConfig :: Explicit {
118
113
format : TransformerInputFormat :: String ,
119
114
src : String :: new ( ) ,
120
115
} ) ,
121
- output : SenderOutputOpts :: Svix ( SvixSenderOutputOpts {
116
+ SenderOutputOpts :: Svix ( SvixSenderOutputOpts {
122
117
token : "" . to_string ( ) ,
123
118
options : None ,
124
119
} ) ,
125
- } ;
126
-
127
- assert_eq ! (
128
- cfg. into_sender_input( )
129
- . err( )
130
- . expect( "invalid config didn't result in error" ) ,
131
- "redis only supports json formatted transformations"
132
120
)
121
+ . err ( )
122
+ . expect ( "invalid config didn't result in error" ) ;
123
+
124
+ assert_eq ! ( err, "redis only supports json formatted transformations" )
133
125
}
134
126
135
127
// FIXME: can't support raw payload access for redis because it requires JSON internally.
136
128
// Revisit after `omniqueue` adoption.
137
129
#[ tokio:: test]
138
130
async fn test_redis_receiver_string_transform_is_err ( ) {
139
- let redis_out = ReceiverOutputOpts :: Redis ( RedisOutputOpts {
131
+ let redis_out = QueueOutputOpts :: Redis ( RedisOutputOpts {
140
132
dsn : "" . to_string ( ) ,
141
133
max_connections : 0 ,
142
134
queue_key : "" . to_string ( ) ,
0 commit comments