Discontinuing a product is a normal commercial decision and it is handled badly often enough that doing it well is a differentiator. Customers who built a process on your software are being told to stop, and how you manage that is observed by everyone else you sell to. A company that ends a product carelessly has told its remaining customers something about what happens if their product becomes unprofitable.
Decide with the whole picture rather than the revenue line. Direct revenue, yes, but also which customers use it as part of a larger relationship, what support burden it carries, what engineering time it consumes, and whether it is the entry point through which customers find your other products. Products that look unprofitable in isolation are sometimes the top of a funnel, and killing them produces a decline nobody attributes to the decision for a year.
Give notice proportionate to what customers must do. If they need to migrate data, select an alternative, change an internal process and retrain staff, ninety days is not generous, it is barely adequate. Twelve months for anything a business depends on operationally. And announce it once, clearly, to everyone at the same time — a decision that leaks to some customers through a support conversation before others hear officially creates the impression of concealment.
Provide the exit rather than describing it. A complete data export in a usable format, documented. A recommendation of alternatives, including competitors, which costs you nothing at this point and is remembered. Help for the accounts that need it, individually. And stop charging before you stop supporting, not the other way round, because the last invoice is what customers remember when they describe the experience to someone else.
Be straightforward about the reason. Customers understand that products get discontinued and they resent being told a decision was made to serve them better when it was made because the product lost money. Saying that it was not commercially sustainable, that you are sorry for the disruption, and that here is what you will do to help, is a position people accept. The alternative language fools nobody and costs the credibility of everything else in the announcement.