31
31
32
32
import org .springframework .core .log .LogAccessor ;
33
33
import org .springframework .lang .Nullable ;
34
+ import org .springframework .pulsar .PulsarException ;
34
35
import org .springframework .util .CollectionUtils ;
35
36
36
37
/**
@@ -102,21 +103,37 @@ public DefaultPulsarProducerFactory(PulsarClient pulsarClient, @Nullable String
102
103
}
103
104
104
105
@ Override
105
- public Producer <T > createProducer (Schema <T > schema , @ Nullable String topic ) throws PulsarClientException {
106
+ public Producer <T > createProducer (Schema <T > schema , @ Nullable String topic ) {
106
107
return doCreateProducer (schema , topic , null , null );
107
108
}
108
109
109
110
@ Override
110
111
public Producer <T > createProducer (Schema <T > schema , @ Nullable String topic ,
111
- @ Nullable ProducerBuilderCustomizer <T > customizer ) throws PulsarClientException {
112
- return doCreateProducer (schema , topic , null , customizer != null ? Collections .singletonList (customizer ) : null );
112
+ @ Nullable ProducerBuilderCustomizer <T > customizer ) {
113
+ try {
114
+ return doCreateProducer (schema , topic , null ,
115
+ customizer != null ? Collections .singletonList (customizer ) : null );
116
+ }
117
+ catch (PulsarException ex ) {
118
+ throw ex ;
119
+ }
120
+ catch (Exception ex ) {
121
+ throw new PulsarException (PulsarClientException .unwrap (ex ));
122
+ }
113
123
}
114
124
115
125
@ Override
116
126
public Producer <T > createProducer (Schema <T > schema , @ Nullable String topic ,
117
- @ Nullable Collection <String > encryptionKeys , @ Nullable List <ProducerBuilderCustomizer <T >> customizers )
118
- throws PulsarClientException {
119
- return doCreateProducer (schema , topic , encryptionKeys , customizers );
127
+ @ Nullable Collection <String > encryptionKeys , @ Nullable List <ProducerBuilderCustomizer <T >> customizers ) {
128
+ try {
129
+ return doCreateProducer (schema , topic , encryptionKeys , customizers );
130
+ }
131
+ catch (PulsarException ex ) {
132
+ throw ex ;
133
+ }
134
+ catch (Exception ex ) {
135
+ throw new PulsarException (PulsarClientException .unwrap (ex ));
136
+ }
120
137
}
121
138
122
139
/**
@@ -134,8 +151,7 @@ public Producer<T> createProducer(Schema<T> schema, @Nullable String topic,
134
151
* @throws PulsarClientException if any error occurs
135
152
*/
136
153
protected Producer <T > doCreateProducer (Schema <T > schema , @ Nullable String topic ,
137
- @ Nullable Collection <String > encryptionKeys , @ Nullable List <ProducerBuilderCustomizer <T >> customizers )
138
- throws PulsarClientException {
154
+ @ Nullable Collection <String > encryptionKeys , @ Nullable List <ProducerBuilderCustomizer <T >> customizers ) {
139
155
Objects .requireNonNull (schema , "Schema must be specified" );
140
156
var resolvedTopic = resolveTopicName (topic );
141
157
this .logger .trace (() -> "Creating producer for '%s' topic" .formatted (resolvedTopic ));
@@ -156,7 +172,12 @@ protected Producer<T> doCreateProducer(Schema<T> schema, @Nullable String topic,
156
172
}
157
173
producerBuilder .topic (resolvedTopic );
158
174
159
- return producerBuilder .create ();
175
+ try {
176
+ return producerBuilder .create ();
177
+ }
178
+ catch (PulsarClientException ex ) {
179
+ throw new PulsarException (ex );
180
+ }
160
181
}
161
182
162
183
protected String resolveTopicName (String userSpecifiedTopic ) {
0 commit comments