Kafka Streams: How to stop stream application when exception - apache-kafka

Version 1.0
Let's say in the punctuate method of lowlevel processor, creation of a dummy file fails with an exception. How to stop the stream application when an exception is encountered?
I was wondering if there is a way to throw an exception, but could not add throw clause on the init method. The following requires to be surrounded by a try-catch OR an exception to be thrown and can't use either one. Please suggest.
Files.createFile(Paths.get(dummyFile));

you could wrap IOException into any unchecked exception like RuntimeException, or would be better to create your own that will extend from RuntimeException, and throw it. if your method throw exception for any incoming message, stream will be in a dead state, so stop consuming messages until you restart application

Related

Custom error conditions to trigger fallback in Hystrix

From the understanding, Hystrix fallback logic is triggered when certain conditions occurred such as Request timeout, thread-pool running at a capacity of 100% or dependency throws exception. Beside these 3 factors can I add more conditions that are also considered as failures such as any specific HTTP Error code like 413 (payload too large)?
The fallback method of Hystrix will be called under the following condition
circuit open
semaphore/thread pool rejection
execution fail (any exception thrown by your method excluding HystrixBadRequestException)
timeout of your method (hystrix timeout)
Only part that is directly related to the user code is execution fail.
In this case, fallback will be triggered by any exception thrown by run() method. It is same for pure Hystrix via HystrixCommand and Hystrix Javanica via annotation.
Only one exception that doesn't trigger HystrixBadRequestException
Therefore, if you want to trigger your fallback also for HTTP 413 status code, all you have to is just throwing any exception inside your method.
If you're using any library that has built-in Hystrix support like Spring Cloud Feign, you need to implement something that library requires. In case of Spring Cloud Feign, you can implement your own ErrorDecoder. The default error decoder will trigger fallback for all 4XX,5XX errors. If you don't want to trigger any fallback 4XX errors except 413, you can throw HystrixBadRequestException inside it.

How to ignore special error in RxJava

I would like to ignore error if it is an instance of for example SpecialError() and not to break the chain.
You can use retry(Predicate<Throwable>) to restart the stream for specific throwables, otherwise it will continue the onError up the chain.
It is impossible to continue a stream after onError has been called however, since the specification defines it as a terminal event.

Entity Framework Best Practice on catch exception

My Entity Framework will always targeting SQL Server.
So, in my program. What type of exception shall I catch?
DataException or SqlException ?
and in DAL, is it good to throw the exception again after logging?
I would suggest multiple catch and log both.
In live environment its not recommended to throw error to client system, however you always need to throw the error.
So its your call how to do it.
If its live show a beautiful error to client that something went wrong and we are looking.

Are exceptions from RPCs the same as normal exceptions?

Trying to understand more about RPCs to answer a homework question: Are exceptions handle the same way for the caller? Are the details of how exceptions are raised on the server any different? Are there any additional differences if you have to rethrow?
OR, can someone just explain what the main differences are between local and remote exceptions? And maybe give an idea of what things to look out for if I wanted to implement remote exceptions.
Here's a simple version of an RPC server / client library:
Server:
try
receive message
deserialize arguments
invoke appropriate method
serialize result
transmit result
catch any Exeption
serialize Exception
transmit Exception
Client (Library code, not the caller):
try
serialize arguments
make remote call
receive "something"
deserialize "something" (could be serialized exception or result)
catch Timeout,Network,Other exceptions not from server
handle whatever the library handles
if deserialized "something" is an exception
rethrow exception from server for caller to catch
else, good/expected results
return results
So, if you want exceptions to be caught by the caller, they possibly differ from regular exceptions in that they must be serialized and transmitted over the network to be re-thrown for the caller.
The caller need not do anything special if the Client library exists. If the client library doesn't exist, then the caller needs to also take the role of the client library. This means that the caller needs to distinguish between serialized results and serialized exceptions (at which point the programmer would probably implement an ad-hoc version of the client library code anyway just to avoid having ugly caller code).
Obviously you can't just use type signatures to distinguish between Exceptions and results (otherwise, what happens if the return type and the exception types for an RPC method were the same?). So there's a tiny bit of overhead in the serialization code for the server to label the different responses.

Generate SoapFault without throwing an exception

I know that when there is an unhandled Exception in asmx that it generates a soapFault and returns it to the client. What I want to know is if there is a way to return a soapFault without throwing an exception. Throwing an exception is an expensive operation and I would like to avoid it if I can.
AFAIK there is no such option (short from building the complete XML/SOAP message yourself that is)... with WCF this could be slightly easier IMO
You can throw a SoapException and can customize it rather thoroughly:
http://support.microsoft.com/kb/833379/en-us
http://msdn.microsoft.com/en-us/library/aa480514.aspx