Functional-Programming exception-processing style with Spring-Integration - functional-programming

How to implement a functional-programming style of exception-processing with Spring-Integration ?
i.e. instead of letting the exception bubble up to the caller or to send it down to a dedicated message-channel, have the error-prone component (e.g. gateway, router etc...) wrap the result/exception with a Option/Either construct and continue to process the rest of the integration-flow.
For example if my integration-flow looks like below, how to wrap the gateway component to pass an Either<Throwable,Object> to the following transformer ?
IntegrationFlows
.from(someChannel)
.gateway(someGateway)
.transform(someTransformer)
.log()
.get()
Subsidiary question: what do you think are the drawbacks of such approach ?
Thanks a lot in advance for your expertise and your time.
Best Regards

Add an ExpressionEvaluatingRequestHandlerAdvice (or a custom advice) to each endpoint.
.gateway(..., e -> e.advice(myAdvice))

Related

How to get Axon event-identifier from the event-store

Just a short question here...
by using Axon, we know that AggregateLifecycle#apply(Object) will be doing the event-sourced for us which under the hood going to persist our event into our event-store.
With regards to that matter, how to get the event-identifier (not the aggregate identifier) once we call that particular apply method ?
Thanks
Based on your another answer, let me suggest you a way to follow.
The MessageIdentifier as used by AxonFramework (AF) is nothing more than an UUID generated for each Message you create.
Since you only need to reuse that info, you can pretty much get it from the Message while handling it. To make things easier for you, Axon provides a MessageIdentifierParameterResolver meaning you can simply use it in any #MessageHandler of you (of course, I am assuming you are using Spring as well).
Example:
#EventHandler
public void handle(Event eventToBeForwarded, #MessageIdentifier String messageIdentifier) {
// forward the event to another broker using the given `messageIdentifier`
}
Hope that helps you and make things clear!

How to invoke an intent through a custom event by calling it from the dialogflow's inline fulfillment code?

Here is the image link of my problem statement better explained through a flow.
problem statement flow
I couldn't understand How this can be achieved.
Just starting with web-hooks and dialog flow.
Thanks in advance
In most cases, you probably don't want or need to trigger a different Intent.
Remember - Intents should match the user's input (usually what they say), not necessarily what you do or how you reply.
If you need to access the database for certain values - access it in the webhook for the Intent where you get the value. If you need to reply certain ways for some values and different ways for others - go ahead and do it.
You can use conv.followup in your dialogflow fulfillment to invoke the intent with custom event as below :
database().ref('/path').on('value', function(snapshot) {
if(snapshot.val == 'val'){
conv.followup('triggering-event'); //enter your event name here
// make sure you have defined the event in the intent to trigger !
}
});
Consider reading this before dealing with intents.
Hope that helps!

Passing the context to the watson conversation

Needing help for passing the context to the Watson conversation at any point in the conversation, without influencing the flow.
it's possible?
Example:
API integration fetches the data and set to the conversation context. Two dialog boxes after I am use the context variable.
Thanks very much
Like #data_henrik said you can pass the context anytime. To take the user input:
{
"context":{
"time":"#sys-time"
},
To use it anywhere use the symbol $. Ex:
condition: if bot recognize $time
Then respond with: The time is #sys-time.

Signalr - Serialize callback as event not a function call?

In Signalr, is there any support for having events instead of callbacks.
Let me explain before you grab your pitchforks.
In following with the first example here
Clients.All.addContosoChatMessageToPage(name, message);
Wouldn't call a hub proxy's addContosoChatMessageToPage(name, message), but would dispatch a addContosoChatMessageToPage event with some extra information. (not asking that it be the same api call exactly)
The reason I'm asking all of this is because
This works much better alongside functional reactive programming frameworks like ELM and bacon.js
I don't want to do this myself and essentially create my own sub-framework. Of course I could always do Clients.All.CreateEvent(name,params...) where I'm continually calling back my method to do this event creation
I actually think events work better in some scenarios for separation of concerns.
Am I crazy? does something like this exist?
This is already supported. If you don't want to do the dispatching yourself and you know the name of the "event" or "method" at runtime you can do this:
IClientProxy proxy = Clients.All;
proxy.Invoke(name, args);
This lets you write code where you may not know the name of the event you're trying to callback on the client at compile time.

When I want one object out of an firebaselistobservable using rxjs, should I still use subscribe?

I am kind of confused about which methods belong with and when to use them.
Right now, I am using subscribe for basically everything and it is not working for me when I want a quick static value out of Firebase. Can you explain when I should use subscribe vs other methods other than for a strict observable?
When working with async values you have a few options: promises, rxjs, callbacks. Every option has its own drawbacks.
When you want to retrieve a single async value it is tempting to use promises for their simplicity (.then(myVal => {})). But this does not give you access to things like timeouts/throttling/retry behaviour etc. Rx streams, even for single values do give you these options.
So my recommendation would be, even if you want to have a single value, to use Observables. There is no async option for 'a quick static value out of a remote database'.
If you do not want to use the .subscribe() method there are other options which let you activate your subscription like .toPromise() which might be easier for retrieving a single value using Rx.
const getMyObjPromise = $firebase.get(myObjId)
.timeout(5000)
.retry(3)
.toPromise()
getMyObjPromise.then(obj => console.log('got my object'));
My guess is, that you have a subscribe method that contains a bunch of logic like it was a ’.then’ and you save the result to some local variable.
First: try to avoid any logic inside the subscription-method -> use stream-operators before that and then subscribe just to retrieve the data.
You much more flexible with that and it is much easier to unit-test those single parts of your stream than to test a whole component in itself.
Second: try to avoid using a manual subscriptions at all - in angular controllers they are prone to cause memory leaks if not unsubscribed.
Use the async-pipe instead in your template and let angular manage the subscription itself.

Resources