@@ -33,16 +33,10 @@ public class UserAttributeChangesSnsHandler {
3333
3434 public UserAttributeChangesSnsHandler (SnsService snsService ) {
3535 this .snsService = snsService ;
36- logger .info ("UserAttributeChangesSnsHandler initialized with SNS service" );
36+ logger .debug ("UserAttributeChangesSnsHandler initialized with SNS service" );
3737 }
3838
39- /**
40- * Event listener that handles user attribute change events asynchronously
41- * This method is triggered whenever a UserAttributeChangedEvent is published
42- *
43- * Now uses the async callback mechanism to avoid blocking the caller thread
44- * during message building and publishing.
45- */
39+
4640 @ EventListener
4741 @ Async
4842 public void handleUserAttributeChanged (UserAttributeChangedEvent event ) {
@@ -72,20 +66,18 @@ public void handleUserAttributeChanged(UserAttributeChangedEvent event) {
7266
7367 Map <String , Object > changedFields = getChangedFields (existingUser , updatedUser );
7468
75- logger .info ("Processing user attribute change event: {} field(s) changed" , changedFields .keySet ());
69+ logger .debug ("Processing user attribute change event: {} field(s) changed" , changedFields .keySet ());
7670
7771 if (changedFields .isEmpty ()) {
7872 logger .debug ("No changes detected, skipping publish" );
7973 return ;
8074 }
8175
82- // Create the MessageBuilder callback that will handle message building asynchronously
8376 MessageBuilder userEventMessageBuilder = () -> {
8477 try {
8578 // Build the complete message structure
8679 Map <String , Object > messageMap = createUserEventMessage (updatedUser , changedFields );
87-
88- // Convert to JsonObject for the callback return type
80+
8981 JsonObject jsonMessage = new JsonObject ();
9082
9183 // Add all fields from the message map to JsonObject
@@ -126,24 +118,19 @@ public void handleUserAttributeChanged(UserAttributeChangedEvent event) {
126118 }
127119 };
128120
129- // Use the new async callback mechanism - this returns immediately
130- // Message building and publishing happens asynchronously
131121 snsService .publishAsync (snsTopicArn , "UAA User Event" , userEventMessageBuilder )
132122 .whenComplete ((publishResponse , throwable ) -> {
133123 if (throwable != null ) {
134- // Enhanced error logging with more context
135124 logger .error ("Failed to publish user event to SNS. " +
136125 "This failure will not affect application functionality." , throwable );
137126 } else {
138- logger .info ("User event published to SNS successfully: messageId={}" , publishResponse . messageId () );
127+ logger .info ("User event published to SNS successfully" );
139128 }
140129 });
141130
142- // This method returns immediately - the message building and publishing continues asynchronously
143131 logger .debug ("Async SNS publish initiated" );
144132
145133 } catch (Exception e ) {
146- // This should only catch synchronous validation errors now
147134 logger .error ("Failed to initiate SNS publish. " +
148135 "This failure will not affect application functionality." , e );
149136 }
0 commit comments