What threatens a programmer with a business process engine using the example of Apache Activiti

The phrase "business processes" has long and strongly excites the brain of all business people and those who are faced with them. Among those interested, it is believed that work on business processes is “stylish, fashionable, youth”. True, there is no guarantee to see a clear understanding of what kind of beast is in the eyes of the interlocutor, even if he is a real business person. And now I propose to imagine what a swamp on this topic croaked in the head of an average developer (for example, the author), when it turned out that the next product will work on these very business processes ...

Inside, it might be interesting to the same developers who still have no idea how business processes will change their lives.

So, starting from this moment, the acquaintance with these poorly understood entities and how they affect the development of the product, why they may be needed and what are useful, began. I want to note that there will be no program code at all - something, but there are practically no technical difficulties there. Normal industrial development. In my case, JavaEE and a bit of Spring.

What is the essence


So, business processes. All my life I was interested in the question “why?” And only then - “how.” Familiarity with business processes was no exception. Therefore, the first point, let's see what is the point. In short - a business process is nothing more than a route between small pieces of work. As with any route, it has its own routes, intersections, the conditions under which you can go, you need to stand or you can only turn left and make a U-turn.

Honestly, here are just a few of the following paragraphs (up to the process description standards) that I consider the most important. And here’s why: in them I’m going to describe what could potentially give the software product the use of the business process engine. Due to a misunderstanding of this, expectations from top management may be overestimated. And, most likely, you will have to say it all out loud in the direction of the above-mentioned people, so that there are no misunderstandings afterwards.

Practical benefit

So: what is the average business process engine, what can it do? His first duty is to understand the drawings drawn by business analysts (or by the developers themselves, depending on who is lucky) in a certain annotation (we will talk a little later) and perform a sequence of actions in a strictly specified order, taking into account all these conditions and ... everything. No, that's really it.

Here we will begin to trample the manager’s fragile soul with a tarpaulin boot: no, the engine will not draw the necessary shapes itself. No he's notwill perform the necessary work for the user if data entry is needed. No, he won’t even write business logic himself, and he really doesn’t know where our base lies and how to access it and invoke our already written business logic. Out of the box, business process engines cannot do all this . All this needs to be written. All that is guaranteed to you is that some framework will take a few resources and go from one class you have implemented to another class you have implemented again according to the scheme you painted again . This may seem obvious, but it's always better to voice it. It will not be worse.

Do we really need it?

Next we need to answer the question - do we need it? It would seem - why learn another book in English, if a simple routing can be assembled on the knee in a week or two. There is still a reason for this (now I will talk about the capabilities of Apache Activiti including, but other representatives are basically no worse).

First of all, you need to decide if you have quite pronounced “cubes” in the product, which can be used and combined repeatedly. If the workflows are defined once and for all with small variations, which are completely covered by infrequent improvements - perhaps all this is unnecessary. In the same case, when there are pronounced pieces of work that constantly have to be connected and the main thing that has to be written is the columns of calls of the previously written logic, perhaps you should pay attention to something like that.

Another reason to think about business processes is when several different people are included in the tasks modeled by the program. Well, something like someone created a document, someone endorsed, someone else wrapped the very first one for revision, and the fourth received a notification that today he would not receive his document under any sauce. This is quite a normal scenario for creating a model of a business process and its subsequent execution by some Activiti.

I have to!

Let us decide that we need it. And the question arose - if almost everything needs to be written by ourselves - do I need to bother with another component of the system with dubious utility? In fact, fully repeating everything that the same Apache Activiti does (hereinafter - simply Activiti) is difficult and long. On points: the main work of what Activiti does:
  • understands the description of the business process in BPMN2 format - without this, it will be necessary to come up with something of your own, which will allow you to set the sequence of actions and not the fact that it will be better than a ready-made standard;
  • saves the history of processes along with time cutoffs * ;
  • takes care of transactions, and there is the possibility of setting up and distributed transactions;
  • supports executor roles (can even connect to LDAP and use user information directly from there) * ;
  • and even the little things are a handful of technological functionality.

Why did I mark with an asterisk points about user roles and stories? Yes, this is infinitely interesting information for business people! You can watch in real time how the processes are going, who is slowing down, where the process may need to be parallelized, how much time is spent on each phase, etc. This information is just a gold mine for process optimization! And based on this information, it will be possible to rebuild the processes of the enterprise, you can say almost on the fly.

Underwater rock

Almost - because all the same, business programmers need to write business logic. If you just need to throw away a piece of work from a certain sequence of actions or change the condition of passing from one point to the second - there are no problems, such a file can really be completed by poking the process diagram with the mouse. But if you need new activity, you need to attract a developer. And it is very important that the customer understands this moment as clearly as possible - the expectation of miracles in our cruel world ends mainly with disappointment and mutual insults. Therefore, the main goal is to convey what the business process engine can really be for free, simply because it exists and what does not. Well, it’s nice to explain that without him, the thing would most likely have not been done by writing a single method in an EJB bean and calling it in the process, but by a full-fledged and more expensive refactoring (after all, everyone knows that the explanation of the benefits without reference to real money that can be saved can not even be voiced, because it is not interesting to anyone).

Those. ultimately, when developers put up with writing virtually stateless operations focused on working in an environment created by a business process engine - changes to customer needs are likely to be faster and easier than without relying on the capabilities of any Activiti (with provided that the application breaks down well into atomic work, of course).

BPMN 2 Description Standard


Let’s now walk a little along the standard for describing business processes. If there is an understanding that the application built for the business process engine will bring success and a bunch of goodies, and not anger and aggression from the customer, the description standard is those opportunities for managing the work flow that are given above and which you need to know. It can be said that this is the second programming language of the project and increased attention to it is strictly necessary. I will make a reservation - here it is only a description of the functional sequence of work.

In fact, there is more than one standard for describing business processes. Not even one. There are BPEL, BPMN1.2, BPMN2, and outside the functional description - all sorts of IDEF0 and EPC. But here we talk about BPMN2. What are its advantages? It is developed enough to describe very weighty processes well, it is both descriptive and executable (in one file information is stored not only about works and their connections, but also the position of these elements in space if someone wants to see a live process diagram) . Well, this is real XML in the end, which allows you to use it whatever you like and edit wherever you want.

Technically, it would be worthwhile to talk about the elements used in BPMN 2.0. But ... the amount of information there is such that under this you have to write a whole bunch of articles. Moreover, right in the documentation of the same Activiti there is a brief description of all the elements, in addition there is a standard fully translated into Russian. The translation was done by EleWis, for which many thanks to her colleagues who do not like languages ​​other than Russian, it is completely calmly searched and downloaded.

In short, there are works, events, logical operators in the standard. The control flow can branch according to conditions, can be parallelized and then converge at one point. In addition to processes, it is possible to call a subprocess. Supported business rules. There are such concepts as compensators (which work in the event of an error and whose task is to respond to this error in a certain way). In couple to compensators there are also error generators. There are even timers. And cycles. And the ability to execute scripts on process variables. Another process can be started not only explicitly, but also on a signal, including from another process. In short, there really is a lot of everything and, perhaps, there was no situation when the set of actions presented by the standard was not enough to conduct the work. Even if at first it seemed like he was a dead end,

Business Process Schema Editor (s)


Yes, schemes. They need to be drawn somewhere - not everyone likes to write XML by hand in vim. If we talk about Activiti - for him (him - because the engine, m.), There is a web application right in the delivery, which works quite well on Tomkat and provides a rather comfortable interface for viewing and editing processes. In addition, there is a plugin for Eclipse. Viewer to IDEA. In general, the BPMN 2 standard is the same standard and should be supported by a whole bunch of corresponding drawings. The last sentence is my naive thoughts that have not stood the test of reality.

Firstly, there are practically no free tools that form a normal document in the BPMN 2 annotation and allow you to save it in the correct XML according to the standard (* .bpmn or .bpmn20.xml) - Aris Express has disappeared. Yaoqiang is not bad (I won’t even try to say THIS), but it is also not completely free. All I wanted was an offline, in the form of a separate application, BPMN editor, which would be convenient and would not lose value from the fields from time to time, as the Eclipse plugin likes to do. But, decent tools were available not only for serious money, but it was also almost impossible to see them. Only after payment. And some supported BPMN. But very, very old.

It was infinitely fun to read the business analyst forums on the topic of editorial choice. A lot of reading came down to the fact that they do not need XML output, but a picture. Those. Visio was among the leaders. And the difficulties of the programmers were not of interest to them.

It just so happened that the complete Activiti web application was the best choice. The main thing is to find a free server for it and, in addition, you can get quite a working option for collaborative and remote work on process diagrams.

BUT! There is also a “second”: all business process engines have their own tags, plus the standard, so it’s better to use the editor created for it. Or add tags later manually - XSD is usually not a problem to get.

Translation difficulties


So, we have come a long way, decided to get involved in business processes, and here, until we get to the details of a particular engine, I consider it my duty to warn of one slippery nuance. The fact is that nowhere in the specification it is written how finely chop the process so that the result has the right to be called Optimal. If the processes will create business analytics - everything will become even more fun, since their task is to accurately reflect the flow of execution from the point of view of a normal person, and no one will take into account that the “Save” operation in two different processes differs radically for a programmer , but is not one and the same. Developers need to be prepared for what will have to be explained on live examples, how the process should be detailed (from their point of view),

And where to see how it is right? I'm afraid that without the accumulation of some experience by the developers themselves - nowhere. You can view a number of examples of processes, make your own by analogy and understand that crushing was insufficient or, conversely, excessive.

Examples:
image

Now imagine: on the right and on the left - the same process (drawn in a whiff for DIA for purely illustrative purposes). And which one is more correct? .. But here it is already decided in a specific case. If for general process control it doesn’t matter why the save could fail, the left option may go. And if everything is important, there will be little right. The main thing is not to reach the limit of fragmentation and not to create tasks containing each line of the simplest code. Usually, this is overkill. But not always, yes ...

Difficulty of choosing


Now let's delve into the selection of a specific implementation. We once settled on Apache Activiti. I don’t even know if it makes sense to give a complete set of reasons. Most likely, no, since some of them were dictated by the very time and place when and under what conditions the selection was carried out. But, in short - a free, responsive forum, development is moving on, you can connect almost everything that starts with the word Apache (and this is a lot: Camel, Karaf, CXF, ...) by simply editing the pom-file. Good CDI support, easy to configure.

In addition to Activiti, there are a number of good solutions. This is Intalio (their paid product is widely known in narrow circles, but there is also a free kernel), there is a solution from JBoss - BPMSuite, there are also paid implementations. If you had to choose a specific implementation again, there is no certainty that it would be Activiti again. Perhaps BPM from JBoss would be chosen. But not a fact. Both products are developing quite dynamically and both provide an untouched field of opportunities. It can be noted that now there is no regret that Activiti was chosen, and not something else. But if someone is going to choose right now - I would strongly recommend not stopping only at Activiti, but at least compare the functionality of the three implementations.

Paid Engines

What is the difference between paid implementations and free ones in all senses? The main difference (except for support 24/7, etc.) can be called the following: they implement what you need to write in free hands. For example, connectors to web services. Developed monitors, showing statistics in a convenient person, rather than DBA, form. Settings using convenient tools.

As mentioned above, statistics are also provided by the free Activiti, and the level of logging is configurable. But in order to show the customer important information for him to optimize the processes and search for applicants for the Slowest Enterprise Brake award - you need to set the developer to write a beautiful wrapper for an existing candy. Paid implementations usually already have something similar.

Also, some customers directly require only commercial product sales. If this is important, you need to look at the paid versions. As an example, you can go to the Intalio website to feel the difference.

Internal implementation difficulties using JSF navigation as an example


Further we move a little away from the general information and get into the wilds of particulars. There will still be no code - I believe that there are no serious technical difficulties in this area; rather, there are difficulties in understanding what is happening and how to live with it further.

What is Activiti from a technical point of view? This is a jar set, i.e. nothing more than a library that you can use as you want: you can connect directly to a web application, you can move it to the model level, or even to a separate server (it has a REST interface, yes). What does this mean in an applied sense: you can remove the load associated with the work of the business process engine on at least another physical server. Activiti out of the box supports clustering well, so there should not be any problems.

In addition, activiti works on its own database scheme - and again we have a choice: you can roll up the table creation scripts directly to your working database, or you can again transfer a separate database to a separate physical server and get independence from the load of Activiti itself applications. This can be very useful if you need to maintain a "thick" history of the processes at a serious load on the main application base. In general, as you want - do it. It can be said that this is the philosophy of most Apache products. You have to pay for it, as always, by reading the configuration documentation. But, in the case of Activiti documentation is not so much. And half of it is generally the BPMN2 standard.

Well, a separate song is the user interface. We used JSF2, which, like any UI, has its own navigation model. And here again, you will need to write an application with an eye on business processes. The reason is that tasks in BPMN2 can basically be divided into two groups: tasks that are performed without user intervention (for example, ServiceTask) and tasks that need user input (UserTask). With the former, everything is simple: you have a piece of somehow shaped code - right down to JavaScript or Groovy in the case of ScriptTask's, in which you can manipulate the variables of the active process. For ServiceTask, this means implementing an ordinary interface that contains one method into which an object will be placed, from which you can access the current instance of the process and into which any CDI bins can be hooked. Any objects can be placed in the process, if only they could serialize. Those. normal operation with preservation of state if necessary. Nothing complicated.

But with the second type of tasks, everything is more complicated. When a process comes across UserTask, it ... just stops and does nothing. A user task is assigned to a specific user or group of them. Next, you need to write your own engine, which will see if there is a task assigned to the user and draw the form in some way. Here and everywhere rummaged withpounding the dog: you need to decide how the UI navigation will work, in other words, or replace the JSF navigation model, shifting this concern to the shoulders of Activiti or ... And the “or” probably will not, because without the ability to redirect the process to the input form, business process management capabilities will be severely curtailed. Only small pieces of work that can be performed blindly, without user intervention, will remain. But the main benefit of business processes can be obtained when several people participate in the process. Therefore, at one time we decided to give the navigation between the forms included in the process to the Activiti side, leaving the JSF navigation models to work with forms that are not included in business processes. And I think that was the right decision.

Otherwise, Activiti is a completely friendly and obvious business process engine that allows you to conduct the interaction of work within the process as clearly as possible.

In conclusion


I hope that everything written above will bring a little more clarity to what business processes are from the point of view of the developer. Well, also quote a certain B. Gates, who previously worked at MicroSoft:
The first rule of any technology is that automating efficiently operations increases efficiency.

Second Rule: Automating Ineffective Operation Increases Inefficiency

Also popular now: