Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Phase4 in a multi threaded environment #92

Closed
chamikaCN opened this issue Jul 22, 2022 · 9 comments
Closed

Using Phase4 in a multi threaded environment #92

chamikaCN opened this issue Jul 22, 2022 · 9 comments
Assignees
Labels

Comments

@chamikaCN
Copy link

Hi Phillip,

I need to run the phase4 project in a multi-threaded environment. I am using the sendMessageAndCheckForReceipt()method to send the AS4 message. But as you have noted, it is non-thread-safe, since the Signal Message Consumer being modified inside the method. What would be the your suggestion to achieve my goal?

PS- I am using phase4 with my own SignalMessageConsumer class, which implements IAS4SignalMessageConsumer, hence the null check aOld == null on line 706 of AbstractAS4UserMessageBuilder.java will always be false.

@phax phax self-assigned this Jul 22, 2022
@phax phax added the question label Jul 22, 2022
@phax
Copy link
Owner

phax commented Jul 22, 2022

Hi @chamikaCN,
Sending multiple AS4 messages in parallel should be no problem, as long as you match the following requirements:

  • Create a separate instance of the client or sender for every thread - so the custom signal message processor is no problem
  • Make sure your signal message processor is either thread safe, or you place a separate instance per thread
  • Make sure the phase4.wss4j.syncsecurity property is set to true - see https://github.com/phax/phase4/wiki/Configuration#phase4-properties

That's all I am aware of

@chamikaCN
Copy link
Author

Thanks @phax

@chamikaCN
Copy link
Author

Hi @phax,

One thing I noticed regarding this issue is that MockServletContext is also not thread-safe and gets created when a message-sending process is initiated in example tests with WebScopeManager.onGlobalBegin (MockServletContext.create ());. I overcame this problem by ensuring only one context was available when threads handle messages and destroying the context if no thread is in execution. Is there a thread-safe implementation of the ServletContext interface included in this project or any workaround you'd like to suggest?

@chamikaCN chamikaCN reopened this Aug 9, 2022
@phax
Copy link
Owner

phax commented Aug 9, 2022

I think the MockServletContext can be made threadsafe quite easily. There is currently no other thread-safe alternative class present - sorry

phax added a commit to phax/ph-web that referenced this issue Aug 9, 2022
@phax
Copy link
Owner

phax commented Aug 9, 2022

Will be part of ph-web 9.6.5 release

@chamikaCN
Copy link
Author

thanks @phax

@phax
Copy link
Owner

phax commented Aug 17, 2022

Sorry I needed to tackle some other things so it is part of the ph-web 9.7.0 release and will be part of the phase4 1.4.0 release

@phax
Copy link
Owner

phax commented Aug 17, 2022

@chamikaCN Release 1.4.0 from https://github.com/phax/phase4/releases/tag/phase4-parent-pom-1.4.0 should fix the concurrency issue. Please note, that this version switched from Apache HttpClient v4 to v5 which might break existing integrations, so be careful.

@chamikaCN
Copy link
Author

Thanks very much for the quick update and the advice as well 🙂 I'll make sure to take precautions prior to upgrading.

@phax phax closed this as completed Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants