This letter introduces a general model of opinion dynamics with opinion-dependent connectivity. Agents update their opinions asynchronously: for the updating agent, the new opinion is the average of the k closest opinions within a subset of m agents that are sampled from the population of size n. Depending on k and m with respect to n, the dynamics can have a variety of equilibria, which include consensus and clustered configurations. The model covers as special cases a classical gossip update (if m = n) and a deterministic update defined by the k nearest neighbors (if m = k). We prove that the dynamics converges to consensus if n > 2(m - k). Before convergence, however, the dynamics can remain for long time in the vicinity of metastable clustered configurations.