To Discuss or Not To Discuss
Find the English version below
Hi ,
Da du treuer Leser meines Newsletter bist, weißt du wahrscheinlich, dass ich Content auf drei verschiedenen Kanälen veröffentliche.
- Montags und Donnerstags kommt dieser Newsletter.
- Dienstags und Freitags ein LinkedIn Post
- Und jeden Mittwoch schreibe ich einen Blog
Jeder Content hat eine andere Zielgruppe
Der Newsletter ist Infotainment. Er soll dich unterhalten, du sollst mit einem neuen Gedanken in den Tag starten. Und du sollst einen tieferen Einblick in meine Gedanken und Perspektiven erhalten.
LinkedIn dient der Reichweite. Am Ende des Tages bin ich Berater und hier ist meist mein erster Kontakt zu Entscheidern.
Und mein Blog ist SEO-optimiert und soll auf gängige Fragen eine schnelle Antwort bieten. (Das war nicht immer so - aber das ist eine andere Geschichte)
Mein gestriger Blog war eine Bredouille
Er behandelt das Event Handling in Spring.
ApplicationEvents
bieten auch die Möglichkeit mit SpEL expressions conditions zu formulieren.
Wenn du zum Beispiel ein CustomSpringEvent
hast:
public class CustomSpringEvent {
private boolean publish;
public CustomSpringEvent(boolean publish) {
this.publish = publish;
}
public boolean isPublish() {
return publish;
}
}
Dann kannst du mit der folgenden Konfiguration dafür sorgen, dass nur Events mit dem publish
flag verarbeitet werden:
@EventListener(condition = "#event.publish")
public void handleEvent(CustomSpringEvent event) {
log.info("handled " + event);
}
Ich will dieses Feature aber nicht propagieren. SpEL expressions werden als String ausgedrückt. Wenn wir also publish
in distribute
umbenennen, dann kann uns der compiler hier nicht helfen. Der code wird immer noch kompilieren. Aber der Code ist fehlerhaft.
SpEL expressions sind ein wunderbares Beispiel für Murphy’s law:
“Anything that can go wrong will go wrong.”
Was soll ich also machen?
Mein Blog ist Anfängercontent. Wer auf diesen Artikel durch Google stößt, der ist noch dabei Grundlagen von Spring zu verstehen.
Wenn ich also das Condition-Feature erkläre, dann wird es benutzt.
Wenn ich aber vollständig ausformuliere, warum man dieses Feature vermeiden sollte, dann ist das out-of-scope.
Aber Anfänger haben auch ein Recht darauf diese Diskussion zu lesen und eine eigene Meinung zu bilden.
Also was soll ich machen? 😕
Ich habe es diesmal nicht ausdiskutiert. Ob das der richtige Ansatz ist? Ich weiß es nicht.
Rule the Backend,
~ Marcus
Hi ,
As you are a loyal reader of my newsletter, you probably know that I publish content on three different channels.
- This newsletter comes out on Mondays and Thursdays.
- A LinkedIn post on Tuesdays and Fridays
- And every Wednesday, I write a blog
Each Content Targets a Different Audience
The newsletter is infotainment. Its purpose is to entertain you, to start your day with a fresh thought. And it allows you to gain a deeper insight into my thoughts and perspectives.
LinkedIn is for reach. At the end of the day, I am a consultant, and this is often where I make my first contact with decision-makers.
And my blog is SEO-optimized, intended to provide quick answers to common questions. (This wasn't always the case - but that's a story for another time)
My Blog Yesterday Was a Puzzle
It covers event handling in Spring.
ApplicationEvents
also provide the option to formulate conditions with SpEL expressions.
For example, if you have a CustomSpringEvent
:
public class CustomSpringEvent {
private boolean publish;
public CustomSpringEvent(boolean publish) {
this.publish = publish;
}
public boolean isPublish() {
return publish;
}
}
Then with the following configuration, you can ensure that only events with the publish
flag are processed:
@EventListener(condition = "#event.publish")
public void handleEvent(CustomSpringEvent event) {
log.info("handled " + event);
}
However, I don't want to promote this feature. SpEL expressions are expressed as a string. So, if we rename publish
to distribute
, the compiler can't help us here. The code will still compile. But the code is flawed.
SpEL expressions are a perfect example of Murphy’s law:
“Anything that can go wrong will go wrong.”
So, what should I do?
My blog is beginner content. Those who come across this article through Google are still trying to grasp the basics of Spring.
If I explain the Condition-Feature, it will be used.
If I explain in detail why this feature should be avoided, then it's out-of-scope.
But beginners also have the right to read this discussion and form their own opinion.
So, what should I do? 😕
This time, I didn't delve into it. Is that the right approach? I don't know.
Rule the Backend,
~ Marcus